研究了一星期多的Osmdroid6.0.2,深感这个开源的android地图包强大,因为使用其他瓦片涉及知识产权,请大家谨慎使用,本文只做研究测试。
新建GoogleTileSource类继承org.osmdroid.tileprovider.tilesource.TileSourceFactory类,具体对应的资源都有注释
public class GoogleTileSource extends TileSourceFactory {
//谷歌卫星混合
public static final OnlineTileSourceBase GoogleHybrid = new XYTileSource("Google-Hybrid",
0, 19, 512, ".png", new String[]{
"http://mt0.google.cn",
"http://mt1.google.cn",
"http://mt2.google.cn",
"http://mt3.google.cn",
}) {
@Override
public String getTileURLString(long pMapTileIndex) {
Log.d("url", getBaseUrl() + "/vt/lyrs=y&scale=2&hl=zh-CN&gl=CN&src=app&x=" + MapTileIndex.getX(pMapTileIndex) + "&y=" + MapTileIndex.getY(pMapTileIndex) + "&z=" + MapTileIndex.getZoom(pMapTileIndex));
return getBaseUrl() + "/vt/lyrs=y&scale=2&hl=zh-CN&gl=CN&src=app&x=" + MapTileIndex.getX(pMapTileIndex) + "&y=" + MapTileIndex.getY(pMapTileIndex) + "&z=" + MapTileIndex.getZoom(pMapTileIndex);
}
};
//谷歌卫星
public static final OnlineTileSourceBase GoogleSat = new XYTileSource("Google-Sat",
0, 19, 512, ".png", new String[]{
"http://mt0.google.cn"