简体   繁体   English

如何在Android中的Google Maps API中使用适合设备像素密度的自定义切片?

[英]How can I use custom tiles that are adapted to the device's pixel density in Google Maps API in Android?

I am writing a Android app that includes a map using the Google Maps API. 我正在编写一个Android应用,其中包含使用Google Maps API的地图。

I load custom map tiles using a my own extension of com.google.android.gms.maps.model.UrlTileProvider . 我使用自己的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. 两组都使用256x256像素的地图图块大小。

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. 然而,在更高密度的设备上(其中许多像素被视为一个逻辑密度无关像素(DiP / DP)),每个地图图块像素被缩放以匹配一个设备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. 我一直在使用UrlTileProvider构造函数宽度/高度玩一会儿,但它们似乎没有任何效果。

And I can not find any settings in the Google Maps API to help me resolve my issue. 我在Google Maps API中找不到任何设置来帮助我解决问题。

I haven't found any solution on stackoverflow or other sites. 我还没有在stackoverflow或其他网站上找到任何解决方案。

Does anyone know how to solve my problem? 有谁知道如何解决我的问题?

您可以从相应的drawable文件夹中将您的切片检索为Drawable ,而不是尝试手动解析分类器。

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. 您可以从缩放级别加载4个图像,然后将它们合并到512 x 512大小的位图中,以便在xhdpi设备上使用。 I would start by checking if TileProvider handles bigger images correctly. 我首先检查TileProvider是否正确处理更大的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android谷歌地图中制作自定义瓷砖 - How to make custom Tiles in android google maps 如何在项目中使用google api强制在android设备选择器中进行Android自动化设备选择 - how can I force Android Automated device selection in the android device chooser with google api's in a project Android在移动设备中使用没有Google帐户的Google Maps API - Android use Google Maps API without Google Account in the mobile device 如何在Android上使用Google Maps Directions API? - How do I use Google Maps Directions API on Android? 如何在 Android Studio 模拟器中使用 Pixel 4(或任何支持 Face ID 的 Android 设备) - How can I use Pixel 4 (Or any Android device that supports Face ID) in Android Studio emulator 如何只用一根手指就能在Google Maps API(android)上旋转? - How can I rotate on Google Maps API(android) with only 1 finger? 如何指定多个Google Maps Android API? - How do I can specific multiple Google Maps Android API? 我可以编辑适用于Android的Google Maps API吗? - Can I edit the Google maps api for android? 在Google地图中使用自定义图块 - Using custom tiles in Google Maps 当我触摸屏幕时,Google Maps Android API v2仅显示图块 - Google Maps Android API v2 only shows tiles when I touch the screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM