我需要在地图视图中添加自定义基础图层。我的理解是地图图块与谷歌图块完全相同。它们是以下列格式提供的静态文件:http:///tilecache///.png
例如,http:///tilecache/6/16/26.png是佛罗里达州阿拉巴马州和密西西比州之间的海湾沿岸。
如何使用图块创建叠加层?
答案 0 :(得分:2)
osmdroid(如上所述)很酷,但非常庞大。前段时间我决定使用http://sourceforge.net/projects/libwlocate/ - 它包含显示/滚动/缩放地图的功能,如osmdroid,但您可以选择使用OSM,Google地图或Google卫星视图。
中找到答案 1 :(得分:1)
我建议使用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";
}
}
然后将您的图块来源添加到地图视图中:
TileSourceFactory.addTileSource(new YourTileSource ("YourTileSource", null, 1, 20, 256, ".png", "http:///tilecache/"));
mapView.setTileSource(TileSourceFactory.getTileSource("YourTileSource"));
你的mapView需要是一个org.osmdroid.views.MapView才能工作。 OSMdroid类应该替换所有谷歌地图类。
首先下载osmdroid-android-3.0.8.jar文件,将其添加到项目的libs文件夹中,然后通过右键单击&gt;将其添加到项目中。属性&gt; Java构建路径&gt;图书馆&gt;添加Jars,然后在libs文件夹中找到它。如果你有更多问题,我有很多osmdroid的经验。
答案 2 :(得分:0)
对于较新版本的OSMDroid,构造函数的 aResourceId 参数已被删除,最后一个参数 aBaseUrl 是 String []
public YourTileSource (String aName,
int aZoomMinLevel,
int aZoomMaxLevel,
int aTileSizePixels,
String aImageFilenameEnding,
String[] aBaseUrl) {
super(aName,
aZoomMinLevel,
aZoomMaxLevel,
aTileSizePixels,
aImageFilenameEnding,
aBaseUrl);
}