我正在开发 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/