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有效,可以迅速加載內存中的瓦片