How can I use custom tiles adapted to the pixel density of a device in the Google Maps API in Android?

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

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

I have two sets of map plates: one is for screens with a higher density and one is for screens with a lower density. A set of tiles with a higher image density has larger text, etc. Both sets use a 256x256 pixel map tile size.

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

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

So far so good.

The corresponding set of map tiles is displayed depending on the density, as it should be.

However, on higher density devices (where many pixels are considered to be one logical density independent pixel (DiP / DP)), each pixel of the map pixel is scaled to correspond to one DiP / DP device. In other words, a higher density device differs in what the cards will look like when rendering.

I played with the width / height of the UrlTileProvider constructor for a UrlTileProvider , but they don't seem to have any effect.

And I can not find any parameters in the Google Maps API to help me solve my problem.

I did not find a solution on stackoverflow or other sites.

Does anyone know how to solve my problem?

+4
source share
2 answers

You can simply extract your tiles as Drawable from the corresponding Drawable folder instead of trying to manually resolve classifiers.

0
source

If you do not control the server, you cannot control the quality.

You can upload 4 images from a magnification level higher than 1 and combine them into a 512 x 512 bitmap for use on xhdpi devices. I would start by checking that TileProvider processes large images correctly.

0
source

Source: https://habr.com/ru/post/1494755/


All Articles