As a developer, I've recently worked on an app development proposal that required integrating Google Maps into a Xamarin.Forms application. While Xamarin.Forms provides its own built-in Map view, it has limited functionality and defaults to using Apple Maps on iOS. This made it unsuitable for my project, so I had to find an alternative.
Fortunately, there's a third-party open-source Google Maps API available for Xamarin Forms, known as Xamarin.Forms.GoogleMaps. This library seems to be pretty full-featured, making it a great choice for anyone looking to integrate Google Maps into their Xamarin.Forms application.
Step 1: Find A Suitable Library
To get started, I downloaded the Xamarin.Forms.GoogleMaps sample project from GitHub and set out to make it work with my project. Thanks to the efforts of GitHub user amay077, this library is a great alternative to the built-in Map view in Xamarin.Forms.
Step 2: Get It To Compile
Once I had the sample project downloaded, I needed to get it compiling. This was relatively straightforward, apart from a few error messages on iOS and Android. On iOS, I encountered an error message indicating that my Xcode version was outdated (I was using Xcode 8.1 at the time). Upgrading to Xcode 8.2 or enabling the managed linker fixed this issue.
On Android, I ran into an error message stating that the Android SDK platform for API Level 23 wasn't installed. To fix this, I installed the appropriate level SDK using the Android SDK Manager or changed my Xamarin.Android project to target a different API version that was already installed (I opted for Android 5.0).
Step 3: Install Google Maps On A GenyMotion Device
To test and develop my application, I decided to use an emulator from GenyMotion. However, by default, GenyMotion doesn't come with Google Play Services installed. To fix this, I followed the instructions on the GenyMotion website to set up Google Play Services on my Android 5.0 device.
Once I had Google Play Services installed, I was able to run the Xamarin.Forms.GoogleMaps sample project and test its functionality. If you're using GenyMotion, be prepared for some irritating popup messages while setting up Google Play Services – but don't worry, it's a minor hassle in the grand scheme of things!
Step 4: Create An Android API Key
To use Google Maps in my application, I needed to create an API key. This involves enabling the Google Maps Android SDK in the Google Developer Console and creating a new API key. To do this, I went to the Dashboard, enabled the API, and then created a new API key by selecting "Restrict Key" and entering the package name and SHA-1 certificate from my error message.
I had to create separate API keys for both the Debug and Release versions of my app, as they have different SHA-1 certificates. Once I had my API keys set up, I embedded them in my AndroidManifest file by adding a few lines of code.
Conclusion
In this article, we've covered the process of integrating Google Maps into a Xamarin.Forms application using the Xamarin.Forms.GoogleMaps library. From finding the right library to creating an Android API key, we've walked through each step in detail. With these steps, you should be able to get started with swift app development and create your own Google Maps-based applications for both Android and iOS.