问题
What is the best way to zoom an MKMapview to closest two or three MKAnnotations for current user location?
I have a list of GPS coordinates (328 to be precise) loaded from a plist, every point is an annotation on the map. I'd like to limit the view to the two nearest annotation points around the user's current location.
回答1:
Roughly, the steps would be:
- Find current location, convert to MKMapPoint
- Iterate your list of annotations, using
MKMetersBetweenMapPoints
to find distance from current location - Save 2 or 3 smallest distances
- Use the largest of these three distances to make a region using
MKCoordinateRegionMakeWithDistance
- Center the map on current location
- Zoom to the region using
[mapView setRegion:region animated:TRUE]
来源:https://stackoverflow.com/questions/12412379/zoom-mkmapview-to-closest-two-mkannotations-for-current-user-location