Cross Platform
Android
iOS
 

Add a Map to an Application

This recipe shows how to add a map to an application using the MapView control.

Recipe



  1. Create a new Xamarin.Android application named AddAMap.
  2. Add a reference to the Mono.Android.GoogleMaps assembly.
  3. Obtain a Google Maps API key (see Obtaining a Google Maps API Key).
  4. 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;
       }
}
  1. 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.