How to Use Google Maps API to Show Google Maps in Xamarin.Forms Maps?
Description
This article describes how to use Google Maps API to show Google Maps using ImageryLayer of the Xamarin Maps(SfMaps) control.
Solution:
You can show the Google Maps using the RequestTileUri event of ImageryLayer.
Step 1: Subscribe the RequestTileUri event of ImageryLayer as demonstrated in the following code example.
XAML:
<maps:SfMaps> <maps:SfMaps.Layers> <maps:ImageryLayer RequestTileUri="ImageryLayer_RequestTileUri"> <maps:ImageryLayer.MarkerSettings> <maps:MapMarkerSetting MarkerIcon="Image" ImageSource="pin.png" IconSize="15"/> </maps:ImageryLayer.MarkerSettings> <maps:ImageryLayer.Markers> <maps:MapMarker Latitude="38.8833" Longitude= "-77.0167"/> <maps:MapMarker Latitude="-15.7833" Longitude= "-47.8667"/> <maps:MapMarker Latitude="21.0000" Longitude= "78.0000"/> <maps:MapMarker Latitude="35.0000" Longitude= "103.0000" /> <maps:MapMarker Latitude="-4.0383" Longitude= "21.7586" /> </maps:ImageryLayer.Markers> </maps:ImageryLayer> </maps:SfMaps.Layers> </maps:SfMaps>
Step 2: In the RequestTileUri event, assign the Google Maps API Uri link (or any tile maps provider) to corresponding x, y, and zoom level of the Uri property of TileUriArgs as demonstrated in the following code example.
C#
/// <summary> /// This event is used to pass the uri of desired maps tile provider. /// </summary> /// <param name="sender">The imagery layer</param> /// <param name="e">The Tile uri arguments</param> private void ImageryLayer_RequestTileUri(object sender, Syncfusion.SfMaps.XForms.TileUriArgs e) { var link = "http://mt1.google.com/vt/lyrs=y&x=" + e.X.ToString() + "&y=" + e.Y.ToString() + "&z=" + e.ZoomLevel.ToString(); e.Uri = link; }
You can download the demo sample from the following link
Conclusion
I hope you enjoyed learning about how to Google Maps API to show Google Maps using ImageryLayer of Xamarin.Forms Maps.
You can refer to our Xamarin.Forms Maps page to know about its other groundbreaking feature representations. You can also explore our Xamarin.Forms Maps Documentation to understand how to manipulate data.
For current customers you can check out on our Xamarin.Forms components from the License and Download page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Xamarin.Forms Maps and other Xamarin.Forms components.
If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!