我有使用4.0版的脱机osmdroid地图。升级到4.1,它们不再有效。我已将问题缩小到XYTileSource,其中aBaseUrl从4.0中的字符串更改为4.1中的数组。如何使脱机磁贴在4.1中工作?
旧的4.0代码有效。瓷砖位于/sdcard/osmdroid/tiles.zip
XYTileSource ts = new XYTileSource ( "tiles",
ResourceProxy.string.offline_mode,
13,
17,
256,
".png",
"http://127.0.0.1");
mapView = (MapView) findViewById(R.id.mapview);
mapView.setTileSource(ts);
mapView.setMultiTouchControls(true);
mapView.setBuiltInZoomControls(false);
mapView.setUseDataConnection(false);
mapView.getController().setZoom(15);
GeoPoint point = new GeoPoint(40.715,-73.945);
mapView.getController().setCenter(point);
我尝试将其更改为此,但它无法正常工作。
String[] urls = {"http://127.0.0.1"};
XYTileSource ts = new XYTileSource ( "tiles",
ResourceProxy.string.offline_mode,
13,
17,
256,
".png",
urls);
答案 0 :(得分:2)
我试着在这里提供一个完整的答案: Download maps for osmdroid
如果您有“旧”tiles.zip,请将其打开,然后检查:
aResourceId和aBaseUrl参数不用于zip文件。
答案 1 :(得分:2)
我发现您使用的是XYTileSource
,默认情况下会扩展OnlineTileSourceBase
。
通过创建Url
课程,我找到了CustomTileSource
问题的解决方法。如下所示:
public class CustomTileSource extends OnlineTileSourceBase {
public static String[] TILE_URL = {"my_url"};
//constructor is default - I changed nothing here
public CustomTileSource (String aName, string aResourceId, int aZoomMinLevel, int aZoomMaxLevel,
int aTileSizePixels, String aImageFilenameEnding, String[] url) {
super(
aName,
aResourceId,
aZoomMinLevel,
aZoomMaxLevel,
aTileSizePixels,
aImageFilenameEnding,
url);
// TODO Auto-generated constructor stub
}
/**
* returns the url for each tile, depending on zoom level
*/
//this is where I changed the return statement to take the first url from the string array of urls
@Override
public String getTileURLString(MapTile aTile) {
return TILE_URL[0] + aTile.getX() + "+" + aTile.getY() + "+" + aTile.getZoomLevel();
}
}
在我的代码中,我需要实例化tilesource,我使用:
CustomTileSource tileSource = new CustomTileSource ("Default", ResourceProxy.string.offline_mode, MIN_ZOOM_LVL, MAX_ZOOM_LVL, DEFAULT_TILE_SIZE, TILE_FORMAT, CustomTileSource.TILE_URL);
//MIN_ZOOM_LVL, MAX_ZOOM_LVL, DEFAULT_TILE_SIZE, TILE_FORMAT are constants that I defined elsewhere
希望它有所帮助。