Zoom MKMapview to closest two MKAnnotations for current user location

Deadly 提交于 2019-12-08 13:28:56

问题


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:

  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]


来源:https://stackoverflow.com/questions/12412379/zoom-mkmapview-to-closest-two-mkannotations-for-current-user-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!