Map pin MarkerClicked event doesn't allow zoom in on pin location
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
Calling MoveToRegion inside a MarkerClicked event doesn't work. When the marker is clicked, it shows the info window, but does not zoom in to the pin as expected.
### Steps to Reproduce
Add a pin to a map. Add a MarkerClicked event to the pin with the following code:
```
Pin pin = (Pin)sender;
MapSpan mapSpan = MapSpan.FromCenterAndRadius(pin.Location, Distance.FromKilometers(1));
map.MoveToRegion(mapSpan);
```
Then click on the pin. The Info window is displayed but map does not zoom in.
### Link to public reproduction project repository
https://github.com/smitha-cgi/MarkerTest.git
_Must fix the API_KEY value in AndroidManifest.xml before building so that map tiles appear_
### Version with bug
7.0
### Last version that worked well
Unknown/Other
### Affected platforms
Android, I was *not* able test on other platforms
### Affected platform versions
Android 11 and up
### Did you find any workaround?
Change MarkerClicked event to use a timer for the MoveToRegion and it will work:
```
IDispatcherTimer timer = Application.Current.Dispatcher.CreateTimer();
timer.Interval = TimeSpan.FromMilliseconds(500);
timer.Tick += (s, e) =>
{
IDispatcherTimer timer = (IDispatcherTimer)s;
timer.Stop();
MapSpan mapSpan = MapSpan.FromCenterAndRadius(_selectedPin.Location, Distance.FromKilometers(1));
MainThread.BeginInvokeOnMainThread(() =>
{
map.MoveToRegion(mapSpan);
});
};
timer.Start();
```
### Relevant log output
_No response_
Contributor guide
Research direction
Start with the public reproduction project linked in the issue, fixing the API_KEY in AndroidManifest.xml so the map can be tested. Reproduce the MarkerClicked and MoveToRegion sequence on Android 11 or later, then compare it with the timer-based workaround. Done means MoveToRegion zooms to the pin from MarkerClicked without requiring a delayed timer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100