ios - 计算距 GPS 位置的距离

标签 ios cocoa-touch location

我正在开发 Xcode 项目,但遇到了一些问题。 在我的应用程序中,我有一个 GPS 位置,并且我在 1000 米半径范围内获得了一些出租车服务。我想找到离我最近的服务。出租车服务位置是从 JSON 解析出来的。看起来像这样

NSNumber * latitude = [[diction objectAtIndex:13]objectAtIndex:1];
NSLog(@"lng is =>%@", latitude);
NSNumber * longitude = [[diction objectAtIndex:13]objectAtIndex:2];
NSLog(@"lat is =>%@", longitude);

此外,我还有自己的位置:

[locationManager stopUpdatingLocation];
NSLog(@"latitude: %f", newLocation.coordinate.latitude);
NSLog(@"longitude: %f", newLocation.coordinate.longitude);

如何减去上面的纬度和经度才能找到最近的服务。 谨致问候。

最佳答案

 CLLocation *oldLocation = [[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]];
    double distance = [newLocation distanceFromLocation:oldLocation];

使用这个可能会对您有所帮助,谢谢。

关于ios - 计算距 GPS 位置的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15215405/

相关文章:

ios - 根据选择的选项以不同的 View 呈现 View Controller : Swift 4

ios - 从在线数据库填充 UICollectionView

iphone - 触发 UIApplicationDidBecomeActiveNotification 后会调用什么?

ios - 统一UIViewController "became frontmost"检测?

ios - 如何在 iOS 中获取表情符号路径

ios - NSTimeInterval 并查看日期是否超过一个小时

objective-c - UIBarButtonItem 不继承 UIView 的原因是什么?

c# - WPF - 设置相对于用户控件的对话框窗口位置

Android onLocationChanged 最快每秒只调用一次

android - react-native-maps 获取当前位置