This demo shows how to use Managed Google Maps API.
It uses Google Maps API which is part of Android SDK add-ons.
Since Mono for Android 1.9.2, we provide Mono.Android.GoogleMaps.dll which is a managed binding to the Java API.
There are four requirements in order to run build and run this sample:
- Mono for Android 1.9.2 or later.
- The Google APIs Android SDK add-on.
- A device with Google Maps support.
- A Google Maps API Key.
In the following sections, $ANDROID_SDK_PATH
is the directory that contains
your Android SDK installation.
The Google APIs require the "Google APIs" add-on library, which is provided for each API level. You need to download it for the API level you wish to target.
To install the Google APIs Android SDK add-on:
- Launch the Android SDK manager:
$ANDROID_SDK_PATH/tools/android
- Within the Android SDK manager, click Available packages in the left-hand pane.
- In the right-hand pane, navigate to the tree view node Third party Add-ons /Google Inc. add-ons (dl-ssl.google.com)
- Select the check-box for e.g. "Google APIs by Google Inc., Android API 8, revision 2".
- Click the Install Selected button in the lower right corner.
- In the "Choose Packages to Install" dialog, select the Accept radio button, then click the Install button.
To verify that your target device has Google Maps support, you can use the following command to see if Google Maps support is present:
$ $ANDROID_SDK_PATH/platform-tools/adb shell ls /system/framework/*map*
/system/framework/com.google.android.maps.jar
/system/framework/com.google.android.maps.odex
The com.google.android.maps.jar
library should be present on
hardware devices, but may not be present within some emulators.
If you need an emulator with Google Maps support:
- Launch the Android AVD manager:
$ANDROID_SDK_PATH/tools/android avd
- Within the Android SDK and AVD manager, click Virtual devices in the left-hand pane.
- Click the New... button on the right-hande side.
- In the Create new Android Virtual Device (AVD) dialog, provide a name for the device (e.g. MAPS), and in the Target drop-down select the Google APIs (Google Inc.) - API Level 8 entry.
- Click the Create AVD button.
You may now launch the emulator with:
`$ANDROID_SDK_PATH/tools/emulator -partition-size 512 -avd MAPS`
Google Maps requires a per-app API key. You can obtain a maps API key from here: http://docs.xamarin.com/android/advanced_topics/Obtaining_a_Google_Maps_API_Key
Once you obtained the key, you have to alter two parts of the sample sources to fully run the demo app:
- in Resource/Layout/Main.axml, replace the
apiKey
attribute value with your API key. - in MapsDemo/MapsViewCompassDemo.cs, replace the second constructor parameter in OnCreate() method.
If you see an empty beige grid, that means the MapsView is working, but you do not have a valid Maps API key.