我知道发布此答案为时已晚,但对其他人来说,它会有所帮助
OpenStreetMap(OSM) 不提供任何航空影像图层(卫星视图)。但是使用 MAPBOX 我们可以在 OSM 中实现卫星视图。
为此,请使用以下代码 sn-p:
在 AndroidManifest 中添加此元数据
<meta-data
android:name="MAPBOX_MAPID"
android:value="satellite-streets-v11"/>
<meta-data
android:name="MAPBOX_ACCESS_TOKEN"
android:value="PUT_YOUR_MAPBOX_ACCESS_TOKEN"/>
如下创建 MapBoxTileSourceFixed.java 类
//waiting for osmdroid #1718 to be fixed:
class MapBoxTileSourceFixed extends MapBoxTileSource {
MapBoxTileSourceFixed(String name, int zoomMinLevel, int zoomMaxLevel, int tileSizePixels) {
super(name, zoomMinLevel, zoomMaxLevel, tileSizePixels, "");
}
@Override public String getTileURLString(final long pMapTileIndex) {
StringBuilder url = new StringBuilder("https://api.mapbox.com/styles/v1/mapbox/");
url.append(getMapBoxMapId());
url.append("/tiles/");
url.append(MapTileIndex.getZoom(pMapTileIndex));
url.append("/");
url.append(MapTileIndex.getX(pMapTileIndex));
url.append("/");
url.append(MapTileIndex.getY(pMapTileIndex));
//url.append("@2x"); //for high-res
url.append("?access_token=").append(getAccessToken());
String res = url.toString();
return res;
}
}
最后在mapview中设置MapBoxTileSource如下
OnlineTileSourceBase MAPBOXSATELLITELABELLED = new MapBoxTileSourceFixed("MapBoxSatelliteLabelled", 1, 19, 256);
((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveAccessToken(this);
((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveMapBoxMapId(this);
TileSourceFactory.addTileSource(MAPBOXSATELLITELABELLED);
map.setTileSource(MAPBOXSATELLITELABELLED);
map.getOverlayManager().getTilesOverlay().setColorFilter(null);
输出:
查看原始存储库here
享受编码:)