使用高德api的tileoverlay層顯示谷歌地圖
阿新 • • 發佈:2019-02-19
private void init() { if (aMap == null) { aMap = mapView.getMap(); setUpMap(); TileOverlay tileOverlay; final String url = "http://mt0.google.cn/vt/lyrs=y@198&hl=zh-CN&gl=cn&src=app&x=%d&y=%d&z=%d&s="; TileProvider tileProvider = new UrlTileProvider(256, 256) { public URL getTileUrl(int x, int y, int zoom) { try { return new URL(String.format(url, x, y, zoom)); } catch (MalformedURLException e) { e.printStackTrace(); } return null; } }; if (tileProvider != null) { tileOverlay = aMap.addTileOverlay(new TileOverlayOptions() .tileProvider(tileProvider) .diskCacheEnabled(true) .diskCacheDir("/storage/emulated/0/amap/cache") .diskCacheSize(100000) .memoryCacheEnabled(true) .memCacheSize(100000)) ; } } }
其中url = http://mt0.google.cn/vt/lyrs=y@198&hl=zh-CN&gl=cn&src=app&x=%d&y=%d&z=%d&s=;
mt0可以取值mt3
lyrs=y為混合地圖,s為衛星地圖,m為普通地圖
優點:
1、可以顯示目前被牆的谷歌地圖,國內無法使用google api
2、準確度看無定位誤差,可使用高德定位SDK,可能和谷歌在中國使用的是高德資料來源有關
缺點:
1、底圖為高德地圖,上層為谷歌地圖,同時載入兩種地圖,浪費系統資源和流量
2、diskcache無效,在sd卡中未找到瓦片地圖的快取,memorycache有效,可以迅速載入記憶體中的瓦片