.Net MAUI - Map marker should stay in center while user is moving the map

I use OpenStreetMap to display a map and there are also some markers shown.

Now I want to give the user the possibility to point to a position on the map:

There should be a red marker in the center of map control.
While the user moves around the map, the red marker should stay in center. We know this from Google Maps.

I should look like screenshot below. How can I achieve this?


map_center.png


3 Replies

VO Vishal Omprasad Syncfusion Team January 14, 2025 10:20 AM UTC

Hi Haimo,

Regarding “marker should stay in center when the user moved the map”:

You can achieve this behavior by using the MapTileLayer.CenterChanged event. This event is triggered whenever the center of the map changes due to user actions such as zooming or panning.

In the CenterChanged event handler, you can get the new center coordinates of the map and update the position of the MapMarker to these coordinates, ensuring the marker remains fixed at the center of the map, as shown in the following code snippet:

[C#]:

private void MapTileLayer_CenterChanged(object sender, Syncfusion.Maui.Maps.CenterChangedEventArgs e)

{

    if (e.Center != null)

    {

        this.mapMarker.Latitude = e.Center.Latitude;

        this.mapMarker.Longitude = e.Center.Longitude;

    }

}

This approach will keep the marker aligned with the center of the map as the user pans or zooms. We have prepared a sample demonstrating this solution, which is attached for your reference. Please review the sample and let us know if it meets your requirements.

If you have any further questions or require assistance with any other aspect, please feel free to reach out. We are here to help.

Regards,
Vishal O.


Attachment: MapMarkerDemo_11a9c3e8.zip


HH Haimo Heymann January 15, 2025 09:51 AM UTC

Hi Vishal,


this is exactly what I was looking for, perfect! Thanks for your quick answer :-)


Regards

Haimo



PR Preethi Rajakandham Syncfusion Team January 16, 2025 04:26 AM UTC

Hi Haimo Heymann,

You're welcome.

We are glad that the provided response meets your requirement. We will mark this thread as solved. Please let us know if you need further assistance. As always, we are happy to help you out. 

Regards,

Preethi R



Loader.
Up arrow icon