我需要添加自定義圖層到我的地圖視圖。我的理解是,地圖貼磚與谷歌貼磚完全相同。它們是以以下格式提供的靜態文件:http:///tilecache///.pngandroid mapview自定義圖塊
例如,http:///tilecache/6/16/26.png是佛羅里達州之間的海灣海岸阿拉巴馬州和密西西比州。
如何使用瓷磚創建疊加層?
我需要添加自定義圖層到我的地圖視圖。我的理解是,地圖貼磚與谷歌貼磚完全相同。它們是以以下格式提供的靜態文件:http:///tilecache///.pngandroid mapview自定義圖塊
例如,http:///tilecache/6/16/26.png是佛羅里達州之間的海灣海岸阿拉巴馬州和密西西比州。
如何使用瓷磚創建疊加層?
osmdroid(如上建議)很酷,但相當巨大。前一段時間,我決定使用http://sourceforge.net/projects/libwlocate/代替 - 它包含顯示/滾動/縮放地圖的功能,如osmdroid,但您可以選擇使用OSM,Google地圖或Google衛星視圖。
我會推薦使用osmdroid。您可以擴展OnlineTileSourecBase。
public class YourTileSource extends OnlineTileSourceBase implements IStyledTileSource<Integer> {
public YourTileSource (String aName, string aResourceId,
int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels,
String aImageFilenameEnding, String aBaseUrl) {
super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels,
aImageFilenameEnding, aBaseUrl);
}
public void setStyle(Integer style) {
// TODO Auto-generated method stub
}
public void setStyle(String style) {
// TODO Auto-generated method stub
}
public Integer getStyle() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTileURLString(MapTile aTile) {
return getBaseUrl() + "/" + aTile.getX() + "/" + aTile.getY() + "/" + aTile.getZoomLevel() + ".png";
}
}
您的瓷磚源然後添加到您的MapView:
TileSourceFactory.addTileSource(new YourTileSource ("YourTileSource", null, 1, 20, 256, ".png", "http:///tilecache/"));
mapView.setTileSource(TileSourceFactory.getTileSource("YourTileSource"));
你的MapView需要有一個org.osmdroid.views.MapView對於工作。 OSMdroid類應該替換所有的Google地圖類。
首先下載osmdroid-android-3.0.8.jar文件,將其添加到項目的libs文件夾中,然後通過右鍵單擊>屬性> Java Build Path> Libraries> Add Jars將其添加到項目中,然後在libs中找到它夾。發佈更多的問題,如果你有他們,我有很多osmdroid的經驗。
中找到OSMDroid的新版本中,aResourceId參數的構造已被刪除,最後一個參數,aBaseUrl,是字符串[ ]
public YourTileSource (String aName,
int aZoomMinLevel,
int aZoomMaxLevel,
int aTileSizePixels,
String aImageFilenameEnding,
String[] aBaseUrl) {
super(aName,
aZoomMinLevel,
aZoomMaxLevel,
aTileSizePixels,
aImageFilenameEnding,
aBaseUrl);
}