Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 计算两组坐标(NSStrings)之间的距离_Objective C_Ios_Xcode_Nsstring_Cllocationmanager - Fatal编程技术网

Objective c 计算两组坐标(NSStrings)之间的距离

Objective c 计算两组坐标(NSStrings)之间的距离,objective-c,ios,xcode,nsstring,cllocationmanager,Objective C,Ios,Xcode,Nsstring,Cllocationmanager,我有两组地理坐标,我正试图计算它们之间的距离。我已经做了一些挖掘,但不知道怎么做。我试图获取用户(userLatitude/userLongitude)和地点(placeLatitude/placeLongitude)之间的距离(以英里为单位)。我的坐标存储为NSString,如下所示。有人知道怎么做吗?谢谢大家! NSString *userLatitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate getU

我有两组地理坐标,我正试图计算它们之间的距离。我已经做了一些挖掘,但不知道怎么做。我试图获取用户(userLatitude/userLongitude)和地点(placeLatitude/placeLongitude)之间的距离(以英里为单位)。我的坐标存储为NSString,如下所示。有人知道怎么做吗?谢谢大家!

NSString *userLatitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate 
getUserLatitude];

NSString *userLongitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate 
getUserLongitude];

NSString *placeLatitude = [element1 objectForKey:@"placeLatitude"];

NSString *placeLongitude = [element1 objectForKey:@"placeLongitude"];

这可能对你有帮助。尝试从您拥有的lat long创建CLLocation

CLLocation* Location1;
CLLocation* Location2;
CLLocationDistance distance = [Location1 distanceFromLocation:Location2];

从下面可以得到距离

CLLocation *locA = [[CLLocation alloc] initWithLatitude:currentLocation.latitude longitude:currentLocation.longitude];

CLLocation *locB = [[CLLocation alloc] initWithLatitude:[[element1 objectForKey:@"placeLatitude"] doubleValue]  longitude:[[element1 objectForKey:@"placeLongitude"] doubleValue]];

CLLocationDistance currentDistance = [locA distanceFromLocation:locB];