xamarin forms map sometimes very slow to update tiles, unless I rotate device

545 Views Asked by At

I am using xamarin forms map for a tracking application, so the view tends to move across the landscape and tiles need to be loaded to show the new area. I am scrolling using map.MoveToRegion

Sometimes the map tiles are loading extremely slowly, to the point where the entire region is just white with no graphics. Initially I thought it was a data speed issue, but it turns out that if I rotate the device, changing the layout landscape/portrait, this makes the map instantly refresh, so the data was apparently available, it was just not being rendered. Zooming can have the same effect, albeit not quite as effectively.

How can I force a refresh, or alternatively just make the map refresh more quickly?

1

There are 1 best solutions below

3
On BEST ANSWER

Turns out the issue is that the way to move the forms.map is by MoveToRegion, and that animates the motion. If the animation takes one second and new positions are being set at a higher, or equal, frequency, the map is effectively always in the middle of an animation.

When the map is animating, it is not willing to refresh the tiles, and so the map eventually becomes blank.

When I rotated the device, this constant animation was interrupted, and it could refresh the tile graphics.

The solution was to make a custom renderer with an alternative - non animated - method to move map focus.

private void moveToFast(Location location)
{
  var update = CameraUpdateFactory.NewLatLng(new 
    Android.Gms.Maps.Model.LatLng(location.Latitude, location.Longitude));
  googleMap.MoveCamera(update);
}

There are plenty of examples of custom map renderes, so I will not post that here. The main takeaway is really just that...

while the map is animating, it will not refresh its tiles, so if you constantly update the map location, you should do so in a non-animated way.