2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
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. C# 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. XAML <maps:ImageryLayer.Markers> <local:CustomMarker Label = "California" Latitude = "37" Longitude = "-120" x:Name="marker" /> </maps:ImageryLayer.Markers> <maps:ImageryLayer.MarkerTemplate> <DataTemplate> <Image HorizontalOptions="Center" Source="{Binding Image}" VerticalOptions="Center" HeightRequest="15" WidthRequest="15"/> </DataTemplate> </maps:ImageryLayer.MarkerTemplate>
Output screenshot
Sample for adding markers at the tapped points: https://github.com/SyncfusionExamples/How-to-add-map-markers-dynamically-at-the-tapped-location |
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
Hi I used this sample, but using Touch Events prevent me from moving around Map without Adding any Markers in both Android and iOS like using Touch events prevent any other Events on Map! Mmm, How could I solve this?