2016-07-03 207 views
4

Google地圖提供幾個月的功能來下載某個地理區域以供以後脫機使用。我在我的應用中使用了谷歌地圖Android API,我發現離線時,與真實的谷歌地圖應用不同,我無法完全放大我的應用中的街道級別,因此可能不會使用下載的數據。在谷歌地圖Android API中使用谷歌地圖離線地圖(緩存)

有沒有辦法讓我的應用程序使用它?

回答

5

您需要創建自己的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 

希望這有助於!

+0

它確實有幫助。非常感謝:) – Phil

+0

這是否違反Google Maps API的使用條款?一些討論在這裏https://stackoverflow.com/questions/6109369/how-to-cache-google-map-tiles-for-offline-usage – Sreekanth