【发布时间】:2016-07-03 10:31:18
【问题描述】:
Google 地图在几个月内提供了下载某个地理区域以供以后离线使用的功能。我在我的应用程序中使用 Google Maps Android API,我看到离线时,与真正的谷歌地图应用程序相比,我无法在我的应用程序中完全放大到街道水平,所以下载的数据可能是未使用。
有没有办法让我的应用使用它?
【问题讨论】:
标签: android google-maps google-maps-android-api-2
Google 地图在几个月内提供了下载某个地理区域以供以后离线使用的功能。我在我的应用程序中使用 Google Maps Android API,我看到离线时,与真正的谷歌地图应用程序相比,我无法在我的应用程序中完全放大到街道水平,所以下载的数据可能是未使用。
有没有办法让我的应用使用它?
【问题讨论】:
标签: android google-maps google-maps-android-api-2
您需要创建自己的TileProvider 并在本地访问磁贴。检查这个documentation。
以下是一些可能对您有所帮助的相关主题:
检查此video tutorial about caching 和此example from GitHub。
您还可以使用osmdroid,它可以替代 Android 的 MapView 类。它还包括一个模块化的瓦片提供系统,支持大量在线和离线瓦片源,并带有用于绘制图标、跟踪位置和绘制形状的内置覆盖层的覆盖层支持。这是tutorial。
org.osmdroid.views.MapView mapView = (org.osmdroid.views.MapView) findViewById(R.id.map_view); //resolve the map view by id given in the layout
mapView.setTileSource(new OnlineTileSourceBase("Google Maps", ResourceProxy.string.unknown, 1, 20, 256, ".png", "http://mt3.google.com/vt/v=w2.97") {
@Override
public String getTileURLString(final MapTile aTile) {
/*
* GOOGLE MAPS URL looks like
* base url const x y zoom
* http://mt3.google.com/vt/v=w2.97&x=74327&y=50500&z=17
*/
return getBaseUrl() + "&x=" + aTile.getX() + "&y=" + aTile.getY() + "&z=" + aTile.getZoomLevel();
}
});
mapView.setUseDataConnection(false); //this actually makes the controller use only offline tiles
希望这会有所帮助!
【讨论】: