By specifying only the top padding, the map view tries to maximize the displayed size of the overlay in the space left over without distorting the map and based on zoom levels it can present. So you don't get close to the desired width and height that you want.
You can control the displayed position of the overlay better if you calculate and specify the padding for all the sides instead of just the top.
However, the map view will still adjust the actually displayed region based on what it can present without distorting the map, etc. but the result should be closer to what you want.
Based on this sentence in your last paragraph:
my aim is simply to tell mapView to draw that route in a frame of say "64 points from the top and with an height of 80 points and a width of 320 points"
here is an example of how you could get close to that result:
MKRoute *rout = obj;
MKPolyline *line = [rout polyline];
CGFloat desiredDistanceFromTop = 64.0;
CGFloat desiredWidth = 320.0;
CGFloat desiredHeight = 80.0;
CGFloat topPadding = desiredDistanceFromTop;
CGFloat leftPadding = (self.mapView.frame.size.width - desiredWidth) / 2.0;
CGFloat rightPadding = leftPadding;
CGFloat bottomPadding = self.mapView.frame.size.height
- topPadding
- desiredHeight;
UIEdgeInsets edgeInsets =
UIEdgeInsetsMake(topPadding, leftPadding, bottomPadding, rightPadding);
[self.mapView setVisibleMapRect:line.boundingMapRect
edgePadding:edgeInsets
animated:YES];
Separately, note that it's not necessary to convert the map rect to a region or to calculate a "fitted" rect/region yourself since:
- You can use
setVisibleMapRect
instead ofsetRegion
. - Both
setVisibleMapRect
andsetRegion
will themselves calculate a "fitted" rect/region given the requested rect/region.