Question

I have an MKMapView behind another view with a transparent portion for viewing.

How can I center the userlocation in mapview in the viewing window on the top view?

See images below for a visual...

This image show the two layers and how they are composed.

Part 1

This image shows the the full picture. You can see the user location beacon pulsing just below the viewing window.

Part 2

I have tried creating a region that fits the userLocation annotation and manually adjusting the regions span deltas to various arbitrary values but that did not do the trick.

MKCoordinateRegion adjustedRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(userLocation, 800, 800)];
adjustedRegion.span.longitudeDelta = 0.005;
adjustedRegion.span.latitudeDelta = 0.005;
[mapView setRegion:adjustedRegion animated:animated];

Any ideas??

Was it helpful?

Solution

MKCoordinateRegion adjustedRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(userLocation, 800, 800)];

// Calculate the offset to scroll up the map. This example is just a rough guess. 
// You should use your concrete UI item's geometry for a more accurate calcluation. 
CLLocationDegrees moveUpDistance = adjustedRegion.span.latitudeDelta / 3 * 2;

// Move the centerfurther down to scroll up the map. 
adjustedRegion.center.latiude = adjustedRegion.center.latitude + moveUpDistance;

[mapView setRegion:adjustedRegion animated:animated];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top