Skip to content
jaakla edited this page Oct 13, 2014 · 3 revisions

Quick guide

Clone this project git clone https://github.com/nutiteq/hellomap3d.git , import HelloMap3D project, compile it using Android SDK and run it on Android device (not emulator). It has basic map viewing and required 3rd party libraries included.

You can use Eclipse with Android SDK, Android Studio or another IDE - steps are the same.

Expected result: http://youtu.be/WzqpEBjx6jg

Step-by-step guide

This is how you can add map to your own app.

1. Prerequisities

  • Install Nutiteq SDK to your project - see Downloads for different options
  • Make sure your AndroidManifest.XML defines permission
<uses-permission android:name="android.permission.INTERNET"/>

2. Define your application main layout as res/layout/main.xml, so it has map element:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
   <com.nutiteq.MapView
    android:id="@+id/mapView"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    />
</LinearLayout>

3. Create map object. Now we can define MapView type of member in your main activity class, load layout and load the MapView from layout. The object is created now.

public class HelloMap3DActivity extends Activity {

    private MapView mapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapView);
...

4. Initialize and start map. Map object itself does not work right away, as it does not have default map source. Two steps are needed here as minimum: (a) define base Projection, (b) define first (base) map layer. We use here vector-based map layer, configuration of it requires that you load and define style for it.

        // Set the base projection, that will be used for most MapView, MapEventListener and Options methods
        EPSG3857 proj = new EPSG3857();
        mapView.getOptions().setBaseProjection(proj);


        // define base layer.
        UnsignedCharVector styleBytes = AssetUtils.loadBytes("osmbright3d.zip");
        if(styleBytes != null){
            MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes);
            MBVectorTileDecoder vectorTileDecoder = new MBVectorTileDecoder(
                    vectorTileStyleSet);
            TileDataSource vectorTileDataSource = new HTTPTileDataSource(
                    0, 14,
                    "http://api.nutiteq.com/v1/nutiteq.mbstreets/{zoom}/{x}/{y}.vt?user_key=15cd9131072d6df68b8a54feda5b0496"
                    );

            VectorTileLayer baseLayer = new VectorTileLayer(
                    vectorTileDataSource, vectorTileDecoder);
            mapView.getLayers().add(baseLayer);
        }else
        {
            Log.e(TAG, "vector style not found");
        }

After this you can start the application on your phone and it should show map. Congratulations!

Clone this wiki locally