如何从当前位置找到最近的纬度和经度?

编程入门 行业动态 更新时间:2024-10-28 17:14:38
本文介绍了如何从当前位置找到最近的纬度和经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个字典,其中包含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.

更多推荐

如何从当前位置找到最近的纬度和经度?

本文发布于:2023-10-30 08:54:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:经度   当前位置   纬度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!