高德地图加载google瓦片方式
首先瓦片 url : url = "http://www.google.cn/maps/vt?lyrs=m&gl=cn&x=%d&s=&y=%d&z=%d";
"http://mt1.google.cn/vt/lyrs=m@167000000&hl=zhCN&gl=cn&x=%d&y=%d&z=%d&s=Galil";
"http://mt2.google.cn/vt/lyrs=m@167000000&hl=zhCN&gl=cn&x=%d&y=%d&z=%d&s=Galil";
"http://mt3.google.cn/vt/lyrs=m@167000000&hl=zhCN&gl=cn&x=%d&y=%d&z=%d&s=Galil";
"http://mt0.google.cn/vt/lyrs=m@167000000&hl=zhCN&gl=cn&x=%d&y=%d&z=%d&s=Galil";
lyrs= 表示的是图层类型,即瓦片类型,具体含义如下:
m:路线图
t:地形图
p:带标签的地形图
s:卫星图
y:带标签的卫星图
h:标签层(路名、地名等)
加载方式 :
image.png添加瓦片 : mTileOverlay = aMap.addTileOverlay(getGooleMapTileOverlayOptions(LANFORM));
移除瓦片 : mTileOverlay.remove();
高德坐标和瓦片的x,y值转换公式 (可以用这个公式做缓存):
/**
* 通过缩放级别和经纬度获取google瓦片的x值
*
* @param zoom 缩放级别
* @param longtitude 经纬度
* @return x
*/
public static int calculateX(int zoom, double longtitude) {
double n = Math.pow(2, zoom);
return (int) (((longtitude + 180) / 360 )* n);
}
/**
* 通过缩放级别和经纬度获取google瓦片的y值
*
* @param zoom 缩放级别
* @param latitude 经纬度
* @return Y
*/
public static int calculateY(int zoom, double latitude) {
double n = Math.pow(2, zoom);
return (int) ((1 - (Math.log(Math.tan(Math.toRadians(latitude)) + (1 / Math.cos(Math.toRadians(latitude)))) / Math.PI)) / 2 * n);
}
将点列表全部显示在地图上 :
LatLngBounds.Builder latLngBounds = new LatLngBounds.Builder();
for (LatLng latLng : points) {
latLngBounds.include(latLng);
}
int padding = Utils.dp2px(30);
mAMap.animateCamera(CameraUpdateFactory.newLatLngBoundsRect(latLngBounds.build(), padding
, padding, padding, padding));
网友评论