Pieter
Pieter

Reputation: 1831

Zoom MKMapview to closest two MKAnnotations for current user location

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.

Upvotes: 0

Views: 955

Answers (1)

highlycaffeinated
highlycaffeinated

Reputation: 19867

Roughly, the steps would be:

  1. Find current location, convert to MKMapPoint
  2. Iterate your list of annotations, using MKMetersBetweenMapPoints to find distance from current location
  3. Save 2 or 3 smallest distances
  4. Use the largest of these three distances to make a region using MKCoordinateRegionMakeWithDistance
  5. Center the map on current location
  6. Zoom to the region using [mapView setRegion:region animated:TRUE]

Upvotes: 1

Related Questions