目标 C:如何列出具有最近地理位置的位置集
我已经编制了包含纬度和经度信息的位置列表。我可以检查根据我当前的位置过滤和填充表格和地图视图中“最近”地理位置列表的最佳方法是什么吗? (或用户输入的目的地)。另外,是否也可以指出我感兴趣的半径是多少?例如,仅选择距我所在位置 5 公里以内的所有最近的书店等,
感谢您对此
振和的建议
I have compiled a list of locations with latitude and longitude information. Can I check what is the best approach to filter and populate the list of "nearest" geolocations in a table and mapview based on my current location? (or a destination entered by a user). Also is it also possible to indicate what is the radius I am interested in? e.g. only select all the nearest bookstores within 5km from my location etc
Appreciate your advice on this
Zhen Hoe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许我遗漏了一些东西,但为什么不将您的位置添加到地图视图中,并将地图置于用户当前位置或他们想要的任何位置的中心呢? MapKit 将为您完成所有计算,并且仅显示靠近中心的计算。用户可以通过放大和缩小来设置自己的半径。 MapKit 正是为此目的进行了高度优化,这就是您可以实时看到“针雨”的方式。
更新:
您也可以采用另一种方式:一旦您在地图上有了注释,您就可以通过以下方式查询地图以查找可见区域中的那些注释:
来自文档:
Maybe I'm missing something, but why don't you just add your locations to a mapView, and center the map on the user's current location or whereever they want? MapKit will do all the calculations for you, and only show the ones near the center. The user can set their own radius by zooming in and out. MapKit is highly optimized for exactly this purpose, that's how you can see the "rain of pins" in real time.
Update:
You can also go the other way: once you have the annotations on the map, you can query the map for those annotations that are in the visible region with:
From the docs:
您可能会发现
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
非常有用http://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/occ/instm/CLLocation/distanceFromLocation:
You may find
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
to be very usefulhttp://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/occ/instm/CLLocation/distanceFromLocation:
haversine 公式 经常用于导航中计算坐标之间的距离。 这是一个用于距离计算的相当不错的资源,甚至还有一个代码半正矢样本(尽管它是用 Javascript 编写的)。
如果您的位置列表相对较小(甚至数百个),您可能只需迭代整个列表并计算每个位置与当前位置之间的距离。
The haversine formula is frequently used to in navigation for calculating distances between coordinates. This is a pretty decent resource for distance calculations, and even has a code sample for haversine (though it is in Javascript).
If your list of locations is relative small (hundreds, even), you can probably just iterate through the whole list and calculate the distance between each place against current location.