How can I add raster data to Here map in Android?

385 views Asked by At

I am developing an Android Application which has a map and I want to add raster data from REST API to the map.

I tried this tutorial: : https://developer.here.com/mobile-sdks/documentation/android/topics/raster-tiles-custom.html

but it is showing only normal simple map and raster data not showing anywhere.

So how can I show raster data in map? Are there any tutorials more helpful than this tutorial?

1

There are 1 answers

4
Artem Nikitin On

For example, if you get your tiles from a 3rd party web service, then very basic example will look like this:

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;
    }

}