A map can be added to a layout using either MapView
or MapFragment
.
<fragment
android:id="@+id/map_fragment"
android:name="com.mapzen.android.graphics.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
# for an API key from the Mapzen developer portal.
You can set your Mapzen API key via an XML string resource. Add a file app/src/main/res/values/mapzen.xml
and copy the following code.
<resources>
<string name="mapzen_api_key">your-mapzen-api-key</string>
</resources>
Alternatively you can set your Mapzen API key via the MapzenManager
class. Just make sure you call the following method prior to calling MapView#getMapAsyc(...)
or creating an instance of MapzenSearch
or MapzenRouter
.
MapzenManager.instance(context).setApiKey("your-mapzen-api-key");
Initialize the map using getMapAsync(OnMapReadyCallback)
.
MapFragment mapFragment = (MapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment);
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override public void onMapReady(MapzenMap map) {
// Map is ready.
}
});
Your map is now ready to use. MapzenMap
is your main entry point to interact with the map.
Most common map operations can be completed using MapzenMap
including setting the position, rotation, zoom, and tilt. You can also load new styles or draw point, line, and polygon overlays.
For advanced use cases you have access the underlying Tangram MapController
instance by calling MapzenMap#getMapController()
. See the Tangram ES Android documentation for more information.