繁体   English   中英

在 Google Maps Android API 中使用 google maps 离线地图(缓存)

[英]Use google maps offline maps (cache) in Google Maps Android API

谷歌地图在几个月内提供了下载某个地理区域供以后离线使用的功能。 我在我的应用程序中使用Google Maps Android API ,我看到离线时,与真正的谷歌地图应用程序相比,我无法在我的应用程序中完全放大到街道水平,因此可能没有使用下载的数据。

我的应用程序有办法使用它吗?

您需要创建自己的TileProvider并在本地访问切片。 检查此文档

以下是一些可能对您有所帮助的相关主题:

查看有关缓存的视频教程来自 GitHub 的此示例

您还可以使用osmdroid ,它是 Android 的 MapView 类的替代品。 它还包括一个模块化的瓦片提供系统,支持大量在线和离线瓦片源,并带有用于绘制图标、跟踪位置和绘制形状的内置覆盖层的覆盖层支持。 这是教程

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

希望这可以帮助!

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM