Quick Tip – Launching Google Maps in Xamarin Forms

When developing mobile applications sometimes we want to take the user to a map when tapping an address/location name. Launching the native map app installed by default (Google Maps in Android/ Maps in iOS) is pretty easy using Xamarin Essentials.

To use this library you can do it in three simple steps:

1-Install the plugin


2-Initialize it (Only on Android)

3-Use it

Forcing to open Google Maps by default on iOS

According to the google’s documentation to open Google Maps on iOS you have to use the Url Scheme comgooglemaps://.

To open a Uri could use the class Device.OpenUri of Xamarin Forms, but we also have to validate if we can open that uri, so it’s better using Launch from Xamarin Essentials.

1-Check if you can open the Google Maps Uri

2-In your Info.plist add the value comgooglemaps to key LSApplicationQueriesSchemes =

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string>
</array>

3-Open the Uri

This Uri will open a GoogleMaps with a placemark in the specified location with a name. In case you want to do some extra options these are a few things you could do:

  • Open a specific view: Pass the parameter &views=traffic
  • Open it with zoom: Pass the parameter &zoom=14
  • Center the map: Pass the parameter &center={latitud},{longitud}

Here is an example of opening the Google Maps app by default and if isn’t installed will open the iOS Maps app:

That’s all for now, you can check the full source code sample here

Happy coding!

You may also like

1 Comment