19

2つの間の距離をメートルで取得するにはどうすればよいCLLocationですか?CLLocationそれを行うための方法を提供していません、それは見ています。

4

5 に答える 5

63
CLLocationDistance distance = [aCLLocationA distanceFromLocation:aCLLocationB];
// distance is a double representing the distance in meters
于 2012-05-03T13:09:00.780 に答える
5
CLLocationDistance distance = [secondLocation distanceFromLocation:firstLocation];  //      distance is expressed in meters

CLLocationDistance kilometers = distance / 1000.0;
// or you can also use this..
CLLocationDistance meters = distance;

NSString *distanceString = [[NSString alloc] initWithFormat: @"%f", kilometers];

flot totaldistancecovered = [distanceString floatValue];

//Now,you can use this float value for addition...
// distanceMoved  should be float type variable which is declare in .h file...

 distanceMoved = distanceMoved + totaldistancecovered ;
 theLabel.text = [NSString stringWithFormat: @"%f meters", distanceMoved];

うまくいけば、これはあなたを助けるでしょう...

于 2012-05-03T13:08:23.790 に答える
3
CLLocation *loc1 = [[CLLocation alloc]  initWithLatitude:dblLatitude longitude:dblLongitude];   
CLLocation *loc2 = [[CLLocation alloc]  initWithLatitude:dblCurrentLatitude longitude:dblCurrentLongitude];
double dMeters = [loc1 distanceFromLocation:loc2];
[loc1 release];
[loc2 release];
于 2012-05-03T13:09:35.650 に答える
2
+ (CLLocationDistance)distanceBetweenCoordinate:(CLLocationCoordinate2D)originCoordinate andCoordinate:(CLLocationCoordinate2D)destinationCoordinate {    
    CLLocation *originLocation = [[CLLocation alloc] initWithLatitude:originCoordinate.latitude longitude:originCoordinate.longitude];
    CLLocation *destinationLocation = [[CLLocation alloc] initWithLatitude:destinationCoordinate.latitude longitude:destinationCoordinate.longitude];
    CLLocationDistance distance = [originLocation distanceFromLocation:destinationLocation];
    [originLocation release];
    [destinationLocation release];

    return distance;
}
于 2012-05-03T13:09:03.940 に答える
1

Swift 3.0

let location1 = CLLocation(latitude: <CLLocationDegrees>, longitude: <CLLocationDegrees>)
let location2 = CLLocation(latitude: <CLLocationDegrees>, longitude: <CLLocationDegrees>)

let distance = location1.distance(from: location2)

distanceメートル単位でDouble

https://developer.apple.com/reference/corelocation/cllocation/1423689-距離

于 2016-11-22T20:00:59.243 に答える