Map control MoveToRegion does not work when map is not visible
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
When the map is loaded, calling MoveToRegion to the current location does not work unless the map is visible. Only tested on Android.
This does not move the region to the current location:
```
private async void OnMapLoaded(object sender, EventArgs e)
{
LocationsMap.IsVisible = false;
Location geoLocation = await Geolocation.GetLocationAsync();
Distance dist = Distance.FromMiles(20);
LocationsMap.MoveToRegion(MapSpan.FromCenterAndRadius(geoLocation, dist));
LocationsMap.IsVisible = true;
}
```
This does move the regions to the current location:
```
private async void OnMapLoaded(object sender, EventArgs e)
{
LocationsMap.IsVisible = true;
Location geoLocation = await Geolocation.GetLocationAsync();
Distance dist = Distance.FromMiles(20);
LocationsMap.MoveToRegion(MapSpan.FromCenterAndRadius(geoLocation, dist));
}
```
### Steps to Reproduce
1. Add a Map control to the XAML page
2. Add the OnMapLoaded event handler
3. Put the non-working code above into the OnMapLoaded event handler (modifying the Map name if needed)
4. Run the app
### Link to public reproduction project repository
https://github.com/danheinz/MAUI_Issues.git
### Version with bug
7.0 (current)
### Last version that worked well
Unknown/Other
### Affected platforms
Android
### Affected platform versions
Android 33
### Did you find any workaround?
No workaround found.
### Relevant log output
```shell
No log.
```
Contributor guide
Research direction
Start with the public reproduction project linked in the issue and run the OnMapLoaded example on Android 33. Compare MoveToRegion behavior when the Map control is hidden versus visible, using the provided steps to reproduce. Done means MoveToRegion moves the map to the requested current location even when the map is initially hidden.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100