将MKMapview缩放到当前用户位置最近的两个MKAnnotations [英] Zoom MKMapview to closest two MKAnnotations for current user location
本文介绍了将MKMapview缩放到当前用户位置最近的两个MKAnnotations的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将MKMapview缩放到当前用户位置最接近的两个或三个MKAnnotations的最佳方法是什么?
What is the best way to zoom an MKMapview to closest two or three MKAnnotations for current user location?
我有一个从plist加载的GPS坐标列表(精确来说是328个),每个点都是地图上的注释.我想将视图限制在用户当前位置附近的两个最近的注释点.
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.
推荐答案
大致而言,步骤将是:
- 查找当前位置,转换为MKMapPoint
- 使用
MKMetersBetweenMapPoints
迭代注释列表,以查找距当前位置的距离 - 保存2或3个最小距离
- 使用这三个距离中的最大距离使用
MKCoordinateRegionMakeWithDistance
来创建区域
- 将地图以当前位置为中心
- 使用
[mapView setRegion:region animated:TRUE]
缩放到该区域
- 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]
这篇关于将MKMapview缩放到当前用户位置最近的两个MKAnnotations的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文