New Fresh deep-dives on cloud, AI, mobile & web now publish on blog.msdevbuild.com Read the latest → Install the app
Xamarin

Getting Started with Google and Bing Maps using Xamarin.Forms

By   Friday, March 3, 2017 comments
reads
React:
Xamarin allows us to integrate maps in our all the platform mobile application. Google and Bing maps combines the power of Xamarin maps. You can show any location on the map, show different routes on the map e.t.c. You can refer below image for quickly learn about map implementation using xamarin.forms .In this Article ,I have shared very detail about xamarin forms maps implementation .


Download Source Code :


Step 1: 

Setup new Xamarin.Forms Application:

Let's start with creating a new Xamarin Forms Project in Visual Studio.
Open Run > Type Devenev.Exe and enter > New Project (Ctrl+Shift+N) - select Portable Blank Xaml App



It will automatically create multiple projects like Portable, Android, iOS, UWP. You can refer to my previous article for more.

How to Create Your First Xamarin.Form Application - http://www.c-sharpcorner.com/article/how-to-create-first-xamarin-form-application/

Note:

UWP is available in Xamarin.Forms 2.1 and above, and Xamarin.Forms.Maps is supported in Xamarin.Forms 2.2 and above so make sure update xamarin Forms nuget package

Step 2: 

Install Xamarin.Forms.Maps nuget Package:

Xamarin.Forms.Maps is a cross-platform nuget package for native map APIs on each platform. Map control android will support google map ,windows and UWP apps will support bing map .

Right Click on Solution > Select “Manage nuget package for project solution “ > Select Xamain.Forms.Maps > Select all the Project > Click on Install


Step 3: Add Maps control in Portable library:

You can design common xaml design to all the platform from portal library.
Add Xamarin.Forms.Maps namespace from MainPage.xaml

xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"

Add customized UI map UI Design like below and if you want show user current add IsShowingUser="True" property from map control.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:DevEnvExeMyLocation"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
x:Class="DevEnvExeMyLocation.MainPage">
<StackLayout VerticalOptions="StartAndExpand" Padding="30">
<maps:Map WidthRequest="960" HeightRequest="700"
x:Name="MyMap"
IsShowingUser="True"
MapType="Street"/>
</StackLayout>
</ContentPage>

You can add following code for Zoom and center the user position from MainPage.cs file

using Xamarin.Forms;
using Xamarin.Forms.Maps;

namespace DevEnvExeMyLocation
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
MyMap.MoveToRegion(
MapSpan.FromCenterAndRadius(
new Position(37, -122), Distance.FromMiles(1)));
}
}
}

Step 4: Generate Google map API Key

Android allows us to integrate Google maps in our applications, so we need to generate an API key, using Google developer account. This article shows you how to generate Google map API key from Google developer account.

Refer from my previous article for generate Google map API Key http://www.c-sharpcorner.com/article/generate-google-api-key-for-xamarin-android-application/

Step 5: Generate Bing Map Application Key

Windows allows us to integrate Bing Maps in our application, so we need to generate an application key using Bing developer account. This article shows you how to generate Bing maps application key from Bing developer account.
Refer from my previous article for generate Bing map API key - http://www.c-sharpcorner.com/article/generate-bing-map-authentication-key-for-windows-based-application/

Step6: 

Update info.plist file from iOS Project :

The start from iOS 8, we need to add below two keys from info.plist file

<key>NSLocationAlwaysUsageDescription</key>
<string>Can we use your location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We are using your location</string>

Step 7: 

Xamarin Forms Map initialization

Xamarin.Forms and Xamarin.Forms.Maps is a two different NuGet package that added to all the project .While Creating Xamarin Forms project automatically xamarin.Forms nuget package was added and initialization code was added to all the project .

We are recently added new xamarin.forms.maps nuget to our project so required to add initialization, after the Xamarin.Forms.Forms.Init method call.

iOS

Go to iOS project > open AppDelegate.cs file > in the FinishedLaunching method > after global::Xamarin.Forms.Forms.Init(); > Add below line code

Xamarin.FormsMaps.Init();

Android

Go to Android project > open MainActivity.cs file > in the OnCreate method > after global::Xamarin.Forms.Forms.Init(this, bundle); > Add below line code

Xamarin.FormsMaps.Init(this, bundle);

I believe, you already generated google API key and add below key from Property/ AndroidManifest.xml under Application Tag

<meta-data android:name="com.google.android.geo.API_KEY "android:value="Add API Key – Refer Step 4" />

Windows ( WinRT ,Windows Phone,UWP) :

Go to Windows project > open MainPage.xaml.cs file > in the MainPage constructor > after LoadApplication() method > Add below line code

Xamarin.FormsMaps.Init("INSERT_AUTHENTICATION_TOKEN_HERE -refer step 5");

Step9: Enable Required Permissions:

You'll also need to enable appropriate permissions on Android and windows project.

Android:

Right-clicking on the Android project and selecting Property > select on Android manifest > Enable the location specified permissions android.


Windows Project:

Open on the windows Package.appxmanifest file > select on Capabilities > Enable the location specified permissions all windows project.


Step10: Location Privacy Setting on Device:

Before debug and run application you need to enable Location on all devices (iOS,Android,Windows)


Step 11: Installing google Play Services from Android Emulator:

Xamarin.Forms 2.2.0 on Android now depends on GooglePlayServices 29.0.0.1 for maps.



Visual Studio Emulator for Android does not include Google Play Services. This means that several APIs, including support for Google Maps, are not supported by default. To install Google Play Services, follow below steps

Download the Google Apps package from Team Android http://www.teamandroid.com/gapps/

Verify Device Android Version like GApps: CyanogenMod 11 / Android 4.4 KitKat and download

Drag and drop the downloaded .zip package into the running android emulator and wait for installation complete



the emulator will shut down and restart. To verify installation, check that the Play Store app ,gmail,etc is visible in the app menu

Now you can start use android emulator
Run Application

After complete all above steps, now you can start run all platform apps


Issues and Resolutions:

I have shared below some implementation, Development, issues and solution


Error:

Building in Android: Java Out of Memory Error

Solution:

Go to Android project options and set, Build/Android Build > Advanced tab > set 1G (or something) in Java heap size.

If you have any question /feedback /issue, write in the comment box
SJ
Suthahar Jegatheesan

Cloud, AI & Mobile Solutions Architect · 18+ years across Azure, Google Cloud and Firebase, C#, Python, .NET MAUI and Flutter. Author of the Xamarin Q&A Book.

More in this series

1 comment:

  1. Nice blog
    Very informative . The concept of using maps with xamarin helped me and Mobile development company Xamarin.Forms 4.0 . Thanks for the blog .

    ReplyDelete

sponsored

What Colleagues Say

“Suthahar is one of the most thorough and knowledgeable cloud architects I’ve worked with. His depth on Azure and ability to make complex mobile solutions work cross-platform is remarkable. He always delivers beyond expectations.”

AT Arun T. Senior Engineering Manager · Direct Manager

“I’ve followed Suthahar’s MSDEVBUILD blog for years — practical, deep, always current. Working alongside him confirmed what I suspected: he’s as sharp in person as on paper, and a genuinely generous mentor and architect.”

RK Rajesh K. Lead Developer · Mindtree

Certifications & Recognition

AZ-300 · Azure Architect Technologies AZ-301 · Azure Architect Design AZ-104 · Azure Administrator Associate AI-100 · Designing Azure AI Solutions DP-900 · Azure Data Fundamentals MCPD · Windows Phone Certified SAFe® 4 Scrum Master

Technical Expertise

☁ Cloud Platforms Microsoft Azure — Expert · 18 yrs App Services · AKS · Functions · Cosmos DB · APIM · Entra ID AWS & Google Cloud — Advanced
πŸ€– AI & Automation Azure OpenAI / GenAI — Advanced · 5 yrs RAG Pipelines · Bot Framework · Cognitive Services · Vision & Speech AI · ML.NET
πŸ“± Mobile Architecture .NET MAUI & Xamarin — Expert · 12 yrs Flutter · Native iOS/Android · Offline-First · Secure Storage & Auth
πŸ”’ Identity & Security Microsoft Entra ID — Expert OAuth 2.0 · OIDC · Zero Trust · Conditional Access · RBAC · Key Vault

Speaking & Community

Microsoft User Group Malaysia Recurring speaker on Azure architecture, AI integration and .NET mobile development across Malaysia and APAC.
Global Azure Bootcamp — Chennai Presented “AI into Xamarin Mobile Apps” at GAB Chennai, part of the worldwide Global Azure community event.
AI & Azure OpenAI Community Events Workshops and live demos on RAG pipelines, AI agents and intelligent workflow automation since 2023.
Mobile & Cloud Workshops — Coimbatore Multi-day deep-dive sessions at GRG Computer Technology, KG Microsoft Innovation Center and RVS College of Arts and Science.
500+Blog Articles
50+Conference Talks
10K+Monthly Readers
30Public Repositories
3Continents Delivered
New home

MSDEVBUILD now publishes on blog.msdevbuild.com

Every new article lands there first — cloud and Azure, AI and GitHub Copilot, .NET MAUI and Flutter, web and Firebase. It installs as an app, opens like a native one and keeps working offline.

MSDEVBUILD Assistant Ask about Suthahar, Azure, AI or mentorship
Hi! I’m a simple FAQ bot for MSDEVBUILD. Tap a question below or type your own.