We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Display google map in Xamarin.Forms SfMaps control

Description

This article describes how to show google map using ImageryLayer of the SfMaps control.

Solution:

You can show google map using ImageryLayer by overriding the GetUri method of imagery layer extension class on each platform’s (Xamarin.Android, Xamarin.iOS, and UWP) custom map renderer.

Step 1: Initialize the map extension class as shown in the following code snippet.

C#

 

Step 2: Override the GetUri method of imagery layer extension and pass the google uri link (any tile maps provider) with corresponding x, y, and zoom level as shown in the following code snippet.

C#

 

Step 3: Add the imagery layer extension class to layers collection of native map control by overriding the OnElementChanged method of each platform’s custom map renderer.

 

You can download the demo sample in this link.

Article ID: Published Date: Last Revised Date: Platform: Control:
8913 07/06/2018 07/06/2018 Xamarin.Forms SfMaps
Did you find this information helpful?
Comments
Shane Coufreur Jan 03, 2019

Everything added to the imagelayer on line 7 of MainPage will be removed by line 16 in CustomMapRenderer.

This solution completely removes the ability to add any custom markers on the map.

Reply
Sheik Syed Abthaheer M [Syncfusion] Jan 04, 2019

Before clearing the Layers collection from maps, you have to assign the old imagery layer properties to new extended  imager layer(ImageryLayerExt). For example, you have to assign old layer markers collection to the ImageryLayerExt’s markers collection to display the marker  as in below code. 


Please use the following code in the CustomMapRenderer.

 

void AddLayer()

{

ImageryLayerExt layer = new ImageryLayerExt();

NativeMap.SfMaps nativeMap = (Control as NativeMap.SfMaps);

var nativeLayer = nativeMap.Layers[0] as NativeMap.ImageryLayer;

if(nativeLayer != null)

  layer.Markers = nativeLayer.Markers;

nativeMap.Layers.Clear();

nativeMap.Layers.Add(layer as NativeMap.ImageryLayer);

}

 

Reply
Add Comment
You must log in to leave a comment

Please sign in to access our KB

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon