2

2セットの地理座標があり、それらの間の距離を計算しようとしています。私はいくつか掘り下げましたが、それを行う方法を理解できません。ユーザー(userLatitude / userLongitude)と場所(placeLatitude / placeLongitude)の間の距離をマイルで取得しようとしています。以下に示すように、私の座標はNSStringsとして保存されます。誰かがこれを行う方法を知っていますか?皆さん、ありがとうございました!

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

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

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

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

2 に答える 2

6

これはあなたを助けるかもしれません。あなたが持っている緯度からCLLocationを作成してみてください

CLLocation* Location1;
CLLocation* Location2;
CLLocationDistance distance = [Location1 distanceFromLocation:Location2];
于 2012-12-16T02:33:37.737 に答える
0

以下から距離を得ることができます。

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];
于 2015-03-03T10:12:33.057 に答える