簡體   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