Hi, I am having trouble finding if this is possible but using the maps component with blazor I need the user to be able to click somewhere on the map and then be able to access the coordinates from that point. Is this possible and if so any help in doing it would be appreciated.
Hi John,
You can get the coordinates of the clicked location in the Maps component by using the “Latitude” and “Longitude” properties in the event argument of the “OnClick” event. Please find the code snippet from the same below.
Code Snippet:
|
@if (show) { <div> Latitude : @Latitude <br /> Longitude : @Longitude </div> } <SfMaps> <MapsEvents OnClick="@OnClickEvent"></MapsEvents> <MapsLayers> <MapsLayer ShapeData='new {dataOptions= https://cdn.syncfusion.com/maps/map-data/world-map.json}' TValue="string"> </MapsLayer> </MapsLayers> </SfMaps>
@code { bool show = false; public double Latitude { get; set; } public double Longitude { get; set; } public void OnClickEvent(Syncfusion.Blazor.Maps.MouseEventArgs args) { show = true; Latitude = args.Latitude; Longitude = args.Longitude; } } |
You can find the sample and video that demonstrates the same from the below link.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp21765832371
Video: https://www.syncfusion.com/downloads/support/directtrac/general/ze/maps-320169268
Please
let us know if you need any further assistance.
Thank you.
A follow up question what is the format of the coordinates and is it possible to define which format I want to use?
Hi John,
The coordinates are usually formatted in decimal degrees. The Maps component does not support any other format definitions. The decimal degree unit is the standard format used across the global map viewer market.
Please let us know if you need any further assistance.