https://github.com/amccool/mapsandlocationdemo_v3
https://github.com/amccool/mapsandlocationdemo_v3
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/amccool/mapsandlocationdemo_v3
- Owner: amccool
- Created: 2016-11-13T16:04:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-11-01T20:12:55.000Z (over 5 years ago)
- Last Synced: 2025-02-03T11:09:58.015Z (4 months ago)
- Language: C#
- Size: 504 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Maps and Location Demo v3
=========================This code shows how to use Google Maps v2 in an Android application. According to the [Android Dashboard](http://developer.android.com/about/dashboards/index.html), about 93% of all Android devices are running Android 4.0.3 (API level 15) or higher so the focus of this sample is on API 15 and higher.
This sample is relevant for users of Xamarin.Android 4.8 or greater.
The `Debug` and `Release` build configurations contain the following projects:
* **LocationDemo** - this project shows how to use the LocationManager to figure out where the device is. This project does not require Google Play Services client library.
* **SimpleMapDemo** - this project demonstrates some of the simple features of Google Maps for Android v2. It does require the Google Play Services client library, and should run on API 15 devices and up.
* **SimpleMapDemo_Froyo** - this project demonstrates some of the simple features of Google Maps for Android v2. It does require the Google Play Services client library, and should run on API 8 devices and up.**Note:** Ensure that the package name of your application is all lower case. Android is very particular and the Google Maps API will not authenticate the API key property if the package name has mixed case.
## Prerequisites
The SimpleMapDemo_Froyo sample uses the Google Play Services NuGet package.
The SimpleMapDemo sample uses the Google Play Services component that is available in the Xamarin Component Store.
You must also have the Google Play Client Services library installed in order to use the Component. You can install this by using the Android SDK Manager. This library is available under the *Extras* folder:

Google Maps v2 API Key
----------------------You must [obtain a new API Key](https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key) for Google Maps v2. API keys from Google Maps v1 will not work.
The location of the debug.keystore file that Xamarin.Android uses depends on your platform:
- **Windows Vista / Windows 7 / Windows 8**: `C:\Users\[USERNAME]\AppData\Local\Xamarin\Mono for Android\debug.keystore`
- **OSX** : `/Users/[USERNAME]/.local/share/Xamarin/Mono for Android/debug.keystore`To obtain the SHA1 fingerprint of the debug keystore, you can use the `keytool` command that is a part of the JDK. This is an example of using `keytool` at the command-line:
$ keytool -V -list -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android
Adding the API Key to your application
--------------------------------------It goes in your application's manifest, contained in the file Properties/AndroidManifest.xml. From there, the Maps API reads the key value and passes it to the Google Maps server, which then confirms that you have access to Google Maps data.
In AndroidManifest.xml, add the following element as a child of the element, by inserting it just before the closing tag
Specifying additional permissions
---------------------------------Besides permissions required by other parts of your application, you must add the following permissions to AndroidManifest.xml in order to use the Google Maps Android API:
Verifying Google Play Services installation on your device or emulator
----------------------------------------------------------------------[Google Play Services](https://play.google.com/store/apps/details?id=com.google.android.gms) must be installed on a device or emulator before Google Maps for Android v2 will work.
Emulators using the [Google APIs Add-On](https://developers.google.com/android/add-ons/google-apis/) with API 17 and higher have Google Play Services included in the Google APIs Add On.
Emulators not using the Google APIs Add-On images, *will not have Google Play Services installed*. The appropriate APKs may be manually installed into the emulator image, but installing Google Play Services is beyond the scope of this example.
If the device does not have Google Play Services installed, you will see a stack trace similar to the following:
com.htc.autotest.dlib.RecordEngine in loader dalvik.system.DexClassLoader@4052ca48Loaded assembly: Mono.Android.Support.v4.dll [External]
Google Play services is missing.
Google Play services is missing.
Google Play services is missing.
Shutting down VM
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$string
at com.google.android.gms.common.GooglePlayServicesUtil.b(Unknown Source)
at com.google.android.gms.internal.d.a(Unknown Source)
at com.google.android.gms.internal.d.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1201)
at android.app.Activity.performStart(Activity.java:3908)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4263)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Sending signal. PID: 19208 SIG: 9
Backwards Compatibility with GingerBread / Froyo
------------------------------------------------Google Play Services is supported on Android 2.2 (API level 8) or higher. This binding will work on these older API's, but some changes must be made to the binding library project and the sample project first:
* Install the [Google Play Services (Froyo) component](https://components.xamarin.com/view/googleplayservicesfroyo/).
* In the MapsAndLocationDemo project, change the target framework to **Android 2.2**.
* In the MapsAndLocationDemo, add a reference to **Mono.Android.Support.V4**.
* In the MapsAndLocationDemo fix the compile errors:
* ChangeFragmentManager
toSupportFragmentManager
* ChangeActivity
toFragmentActivity
* ChangeMapFragment
toSupportMapFragment
* Changeusing Android.App;
tousing Android.Support.V4.App;
At this point the projects will run on Android 2.2 and Android 2.3 devices.
#Troubleshooting
##AAPT.EXE location incorrect
Google changed the location of certain tools in r22 of the Android SDK (release in mid-May, 2013), which may cause Xamarin.Android to report this error. The forum post [aapt.exe location incorrect](http://forums.xamarin.com/discussion/comment/15360/#Comment_15360) contains some helpful advice for dealing with this issue.
##"does not implement inherited abstract member" compile error
This error is typically caused by one of two things:
1. **Out of date version of Xamarin.Android** - As of June 13, 2013 please use Xamarin.Android 4.6.8 from the Stable update channel. Older versions of Xamarin.Android do not seem to work. The Beta and Alpha channels do not receive the same level of QA. Care and patience are required if you wish to use the Alpha or Beta builds for production applications.
2. **A stale `google-play-services_lib` directory** - Ensure that you have an up-to-date version of the Google Play Services library via the Android SDK manager, and ensure that the Android Library project that your project is using is also up to date. The forum post [Google Maps v2 and "does not implement inherited abstract member" messages](http://forums.xamarin.com/discussion/5030/google-maps-v2-and-does-not-implement-inherited-abstract-member-messages) will also be useful in troubleshooting this issue.