Question

I've a MKMapView that shows a route between two points. These points can change so I wanted the MapView to zoom in that it shows the complete route. I fixed it with this code:

_map.SetVisibleMapRect(_routeOverlay.BoundingMapRect, true);

Now I want some padding around the edges because the route is now very close to the edges of the screen. How can I add padding to the MapView?

PS. I got it working in native iOS Xcode with this code but I can't get it working with Xamarin and C#:

[self.mapView2 setVisibleMapRect:[_routeOverlay boundingMapRect] edgePadding:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0) animated:YES];
Was it helpful?

Solution

I finally fixed it after a few errors. I just had to add UIEdgeInsets to my SetVisibleMapRect() like this:

_map.SetVisibleMapRect (_routeOverlay.BoundingMapRect, new UIEdgeInsets(20, 20, 20, 20), true);

Thanks @Jason for pointing me in the right direction.

OTHER TIPS

There is an overload for SetVisibleMapRect() that does this:

public virtual void SetVisibleMapRect (MKMapRect mapRect, MonoTouch.UIKit.UIEdgeInsets edgePadding, bool animate)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top