Download Code

Xamarin Google Map Example Android

In this tutorial you will learn how to develop xamarin google map example android application.

Google Map

You can learn more about Xamarin Google Map Android in detail from Google Official Documentation or Xamarin Official Documentation.

Create new android application project.

First you will download Google_Play_Sevices library.Go to Tool > Android SDK Manager and hit install.

xamarin Google Map example android, xamarin Google Map Tutorial, xamarin Google Map android, Xamarin Google Map example, how to generate api key in xamarin android, google map in xamarin,how to animate camera to marker xamarin, how to add marker on google map in xamarin android, how to add google play services library in xamarin,

Next is to import that Google Play Services in Xamarin project.So, for that purpose right click on Components > Get More Components.Then a new tab will show up.Click on Get More Components,type Google Play Services – Map and add to project.What’s the effect of adding this component in your project,It will add google map classes in your project.

xamarin Google Map example android, xamarin Google Map Tutorial, xamarin Google Map android, Xamarin Google Map example, how to generate api key in xamarin android, google map in xamarin,how to animate camera to marker xamarin, how to add marker on google map in xamarin android, how to add google play services library in xamarin,

Then rebuild the whole project.

You will generate Google Map API key which you will use to load maps.For that purpose go to Google Developer Console and Sign In.

Create new project by clicking API Project option on right top corner or left top corner.

xamarin Google Map example android, xamarin Google Map Tutorial, xamarin Google Map android, Xamarin Google Map example, how to generate api key in xamarin android, google map in xamarin,how to animate camera to marker xamarin, how to add marker on google map in xamarin android, how to add google play services library in xamarin,

After creating project it will take you to the api’s screen.Now you will see Google Maps Android API Under Google Maps API.Click on Google Maps Android API and enable it.

When you enabled Android Maps API then generate API Key.Go to Credentials in the left hand side Navigation.

When you click Credentials it will show you a window to generate key.Create Credentials > API Key click API Key.

xamarin Google Map example android, xamarin Google Map Tutorial, xamarin Google Map android, Xamarin Google Map example, how to generate api key in xamarin android, google map in xamarin,how to animate camera to marker xamarin, how to add marker on google map in xamarin android, how to add google play services library in xamarin,

New window will appear select Android Key.

xamarin Google Map example android, xamarin Google Map Tutorial, xamarin Google Map android, Xamarin Google Map example, how to generate api key in xamarin android, google map in xamarin,how to animate camera to marker xamarin, how to add marker on google map in xamarin android, how to add google play services library in xamarin,

After selecting Android Key fill below form with your android package name and SHA-1 fingerprint.

xamarin Google Map example android, xamarin Google Map Tutorial, xamarin Google Map android, Xamarin Google Map example, how to generate api key in xamarin android, google map in xamarin,how to animate camera to marker xamarin, how to add marker on google map in xamarin android, how to add google play services library in xamarin,

How to get package name of your project?

Right click on project go to Options > Android Application > package.

Next SHA-1 Generation process please follow the steps carefully.

  • Open your Command Prompt and locate this path using Command Prompt.Path ( C:\Program Files\Java\jdk1.8.0_45\bin).
  • After paste this keytool query ( keytool.exe -list -v -keystore “%LocalAppData%\Xamarin\Mono for Android\debug.keystore” -alias androiddebugkey -storepass android -keypass android ).
  • Don’t use keytool query of Eclipse or Android Studio.Xamarin is different from them.
  • Hit enter.You will find SHA-1 copy and paste in project fingerprint and hit create.Copy that api key and keep it safe.

Go to Main.axml in your project and add Fragment.

xamarin Google Map example android, xamarin Google Map Tutorial, xamarin Google Map android, Xamarin Google Map example, how to generate api key in xamarin android, google map in xamarin,how to animate camera to marker xamarin, how to add marker on google map in xamarin android, how to add google play services library in xamarin,

Now go to your MainActivity.cs class.Do the Following steps.

  • Create variable of Google Map ,MapFragment class.
  • Create a method name initializeMap().
  • Check if googleMap is null else refer the fragment in xml.
  • Set Latitude and Longitude.
  • Set MarkerOption with Latitude,Longitude and Title.
  • Set camera position to that particular co-ordinates.
  • And add marker to google map.

MainActivity.cs

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Gms.Maps;
using System;
using Android.Gms.Maps.Model;

namespace MyMap
{
	[Activity(Label = "MyMap", MainLauncher = true, Icon = "@mipmap/icon")]
	public class MainActivity : Activity,IOnMapReadyCallback
	{
		private GoogleMap google;
		// latitude and longitude
		double latitude = 33.601091;
		double longitude = 73.048278;
		MapFragment mapFrag;

		protected override void OnCreate(Bundle savedInstanceState)
		{
			base.OnCreate(savedInstanceState);

			// Set our view from the "main" layout resource
			SetContentView(Resource.Layout.Main);
			initializeMap(); //calling map

		}

		/**
 		* 	function to load map.
 		* */

		public void initializeMap()
		{
			LatLng location = new LatLng(latitude, longitude);  // setting latitude and longitude
			// getting MapFragment
			mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
			// setting MapFragment to googleMap variable
			google = mapFrag.Map;


			if (google != null)
			{
				google.MapType = GoogleMap.MapTypeNormal;  // setting map type

				// creating marker

				MarkerOptions marker = new MarkerOptions()
					.SetPosition(new LatLng(latitude, longitude))
					.SetTitle("Android Codec");
				//positioning camera according to marker
				CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
				builder.Target(location);
				builder.Zoom(18);
				builder.Bearing(155);

				CameraPosition cameraPosition = builder.Build();
				CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
				google.MoveCamera(cameraUpdate);  // move camera to marker
				google.AddMarker(marker);    // add marker to google Map
			}
		}
		public void OnMapReady(GoogleMap googleMap)
		{
			google = googleMap;
		}

	}
}

Next go to your Android Manifest.xml file.Add permission and map api key.

xamarin Google Map example android, xamarin Google Map Tutorial, xamarin Google Map android, Xamarin Google Map example, how to generate api key in xamarin android, google map in xamarin,how to animate camera to marker xamarin, how to add marker on google map in xamarin android, how to add google play services library in xamarin,

Now run your android application project.

xamarin Google Map example android, xamarin Google Map Tutorial, xamarin Google Map android, Xamarin Google Map example, how to generate api key in xamarin android, google map in xamarin,how to animate camera to marker xamarin, how to add marker on google map in xamarin android, how to add google play services library in xamarin,

That’s it for this tutorial Xamarin Google Map Example Android.

For Java example visit Android Codec.

Thanks.