我有一个字典,其中包含n个纬度,经度和地址的集合。我想计算哪个(纬度和纬度)点与ios中当前用户位置(纬度,纬度)最接近?
I have a dictionary with a collection of n number of latitude, longitude and address. I want to calculate which (latitude and langitude)point is closest from current user location(latitude ,langitude) in ios?
提前致谢
推荐答案如果你想根据坐标计算,这里是一个简单的场景:只需要取出所有你的词典中的CLLocationCoordinate2D。
If you want to calculate based on the co-ordinates , here is simple scenario : Just take all of the "CLLocationCoordinate2D" from your dictionary .
例如:
MKPointAnnotation *annotaion=[MKPointAnnotaion alloc]alloc]; CLLocationCoordinate2D pointACoordinate = [annotation coordinate]; // If you have the co-ordinates in hand , then just make " CLLocation *loc2; " using Co-ordinates loc2 = [[CLLocation alloc] initWithLatitude:pointACoordinate.latitude longitude:pointACoordinate.longitude];然后通过与使用此
then put loop or whichever you want to calculate the less distance by comparing with all using this
CLLocationDistance nearLocation=[ location distanceFromLocation:loc2]; // location --> your current Location如果您想实现其他目的:那么只需按照秋刀鱼回答,他们很好地实现了。
If you want to achieve other than it : Then just follow saury answer, they are good to achieve perfectly.
更多推荐
如何从当前位置找到最近的纬度和经度?
发布评论