Articles in this section
Category / Section

How to add map markers dynamically to the tapped location

1 min read

Using SfMaps, you can add markers dynamically to the desired location just by tapping at the required locations. You can achieve this by converting the screen points to the corresponding latitude and longitude coordinates and add markers to the maps.


The following code snippet demonstrates how to add markers to a layer.


public void AddMarker()
    var layer = this.Layers[0];
    Point longitudeLatitude = layer.GetLatLonFromPoint(new Point(PointX, PointY));  // Getting longitude and latitude values from touch points.
    layer.Markers.Add(new CustomMarker()
        Latitude = longitudeLatitude.Y.ToString(),
        Longitude = longitudeLatitude.X.ToString()


Markers can be specified as demonstrated in the following code snippet.


                    <local:CustomMarker Label = "California" Latitude = "37" 
                                    Longitude = "-120" x:Name="marker" />
                        <Image HorizontalOptions="Center" 
                               Source="{Binding Image}"
                               VerticalOptions="Center" HeightRequest="15" WidthRequest="15"/>


Output screenshot

Adding Markers at tapped points using Xamarin SfMaps


Sample for adding markers at the tapped points:

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Please  to leave a comment
Access denied
Access denied