Priority
Priority

Reputation: 11

Set region by distance between two points

I have the first point in center of MKMapView and distance in meters to map's left border that the center should be.

How do I set the region for that?

Upvotes: 0

Views: 1494

Answers (1)

user467105
user467105

Reputation:

Given the center coordinate and the distance in meters from the center to the border, you can use the MKCoordinateRegionMakeWithDistance function to create the region:

CLLocationCoordinate2D centerCoord = CLLocationCoordinate2DMake(lat, lng);

CLLocationDistance centerToBorderMeters = 5000;

MKCoordinateRegion rgn = MKCoordinateRegionMakeWithDistance 
                           (centerCoord, 
                            centerToBorderMeters * 2,   //vertical span
                            centerToBorderMeters * 2);  //horizontal span

[mapView setRegion:rgn animated:YES];

Upvotes: 1

Related Questions