4

I am writing a Android app that includes a map using the Google Maps API.

I load custom map tiles using a my own extension of com.google.android.gms.maps.model.UrlTileProvider.

I have two sets of map tiles: one designed for higher density screens and one designed for lower density screens. The higher density map tile set features larger text and so on. Both sets use map tile size of 256x256 pixels.

I switch between the two sets depending on screen density as obtained from:

DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
Float density = displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT;

So far so good.

The appropriate map tile set is displayed depending on density, as it should.

However, on higher density devices (where many pixels are treated as one logical density-independent-pixel (DiP/DP)) each map tile pixel is scaled to match one device DiP/DP. In other words the higher density the device features the worse the map tiles will look when rendered.

I have been playing around for a while with the UrlTileProvider constructor width/height, but they do not seem to have any effect.

And I can not find any settings in the Google Maps API to help me resolve my issue.

I haven't found any solution on stackoverflow or other sites.

Does anyone know how to solve my problem?

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • 1
    Have you tried using different image sizes for different DPI? 384 for HDPI, 512 for XHDPI, etc. – MaciejGórski Aug 01 '13 at 15:27
  • @MaciejGórski: Thanks for the response! I'm afraid your suggestion cannot be a solution in my case because the map tiles are loaded from an external service that I do not own. However, your suggestion would be worth looking into if you do control the map tile service. – Steinar Henriksen Aug 05 '13 at 06:31
  • Have you found a solution Steinar? – aez Nov 30 '14 at 20:00

2 Answers2

0

You can just retrieve your tiles as a Drawables from corresponding drawable folder, instead of trying to manually resolve classifiers.

Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146
  • Unfortunately the tiles aren't located in my drawables folders, but loaded from an external service. There's a lot of tiles so it has to be that way. Also the Google Maps API for Android only supports loading custom map tiles from implementations of TileProvider ([link](http://developer.android.com/reference/com/google/android/gms/maps/model/TileProvider.html)). It seems to me that the Google Maps API for Android always displays 1 tile pixel as 1 dip. – Steinar Henriksen Aug 05 '13 at 07:44
0

If you don't control server then you cannot control the quality.

You could load 4 images from zoom level higher by 1 and merge them into a bitmap of size 512 x 512 to use on xhdpi devices. I would start by checking if TileProvider handles bigger images correctly.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94