将MKMapview缩放到当前用户位置最近的两个MKAnnotations [英] Zoom MKMapview to closest two MKAnnotations for current user location

查看:72
本文介绍了将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.

推荐答案

大致而言,步骤将是:

  1. 查找当前位置,转换为MKMapPoint
  2. 使用MKMetersBetweenMapPoints迭代注释列表,以查找距当前位置的距离
  3. 保存2或3个最小距离
  4. 使用这三个距离中的最大距离使用MKCoordinateRegionMakeWithDistance
  5. 来创建区域
  6. 将地图以当前位置为中心
  7. 使用[mapView setRegion:region animated:TRUE]
  8. 缩放到该区域
  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]

这篇关于将MKMapview缩放到当前用户位置最近的两个MKAnnotations的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆