我正在开发一个包含地图的Android应用程序,我想将REST API中的栅格数据添加到地图中。
我尝试了这个教程:https://developer.here.com/mobile-sdks/documentation/android/topics/raster-tiles-custom.html
但它只显示普通的简单地图和栅格数据,不显示在任何地方。
那么如何在地图中显示栅格数据呢?有没有比本教程更有帮助的教程?
答案 0 :(得分:0)
例如,如果您从第三方Web服务获取磁贴,那么非常基本的示例将如下所示:
TilesActivity.java
public class TilesActivity extends Activity {
private Map map;
private MapFragment mapFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //put your layout there
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
mapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(Error error) {
if (error.equals(Error.NONE)) {
map = mapFragment.getMap();
LiveMapRasterTileSource tiles = new LiveMapRasterTileSource();
map.addRasterTileSource(tiles);
} else {
Log.d(TAG, "ERROR: " + error);
Log.d(TAG, error.getDetails());
Log.d(TAG, error.getStackTrace());
}
}
});
}
}
LiveMapRasterTileSource.java
public class LiveMapRasterTileSource extends UrlMapRasterTileSourceBase {
private final static String BASE_URL = "http://example.com";
public LiveMapRasterTileSource() {
// you can set different options there, look at
// https://developer.here.com/mobile-sdks/documentation/android/topics_api_nlp/com-here-android-mpa-mapping-maprastertilesource.html#topic-apiref
// for details
setOverlayType(MapOverlayType.BACKGROUND_REPLACEMENT);
setTransparency(Transparency.ON);
setCachingEnabled(true);
}
// Implementation of UrlMapRasterTileSourceBase
public String getUrl(int x, int y, int zoomLevel) {
String request = String.format("?zoom=%d&coord1=%d&coord2=%d", zoomLevel, y, x);
return BASE_URL + request;
}
}