This recipe shows how to add a map to an application using the MapView control.
Recipe
- Create a new Xamarin.Android application named AddAMap.
- Add a reference to the Mono.Android.GoogleMaps assembly.
- Obtain a Google Maps API key (see Obtaining a Google Maps API Key).
- Change the base class of Activity1 to Android.GoogleMaps.MapActivity and add an implementation for the abstract member, IsRouteDisplayed.
protected override bool IsRouteDisplayed { get { return false; } }
- Add a MapView to Main.axml using your Maps API key.
<com.google.android.maps.MapView android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:apiKey="Insert API Key here" />
You can also add a map in code like this:
var map = new MapView (this, "Insert API Key here");
Additional Information
The MapView class is part of the Google Add-On APIs. To use it in an emulator, the emulator will need to have these APIs included. For more information see the Maps and Location document.