How do can I add 2 miles to viewRegion.span.latitudeDelta?
How do can I add 2 miles to viewRegion.span.latitudeDelta ? How do can I calculate kTwoMiles?
MKCoordinateRegion viewRegio开发者_开发技巧n;
viewRegion.center = coordinateCentre;
viewRegion.span.latitudeDelta = latitudeMax - latitudeMin + kTwoMiles;
viewRegion.span.longitudeDelta = longitudeMax - longitudeMin + kTwoMiles;
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
[mapView setRegion:adjustedRegion animated:YES];
Basically this is relatively complicated because every degree has a different delta.
At Earth's equator you will have 111 km per degree and at the poles 0 km. (http://en.wikipedia.org/wiki/Longitude#Degree_length)
I decided to add 2 miles only in the latitudeDelta. Probably regionThatFits will resize longitudeDelta.
double kTwoMiles = (double)2/69;
MKCoordinateRegion viewRegion;
viewRegion.center = coordinateCentre;
viewRegion.span.latitudeDelta = latitudeMax - latitudeMin + kTwoMiles;
viewRegion.span.longitudeDelta = longitudeMax - longitudeMin;
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
[mapView setRegion:adjustedRegion animated:YES];`enter code here`
精彩评论