Jak mogę uzyskać odległość w metrach między dwoma CLLocation
s? CLLocation
nie zapewnia żadnej metody, aby to zrobić, to seeems.Jak mierzyć odległość w metrach między dwoma CLLOCATIONS?
17
A
Odpowiedz
56
CLLocationDistance distance = [aCLLocationA distanceFromLocation:aCLLocationB];
// distance is a double representing the distance in meters
+2
http://developer.apple.com/library/ios/DOCUMENTATION/CoreLocation/Reference/Classocation_Class/Clococation/CLLocation.html#//apple_ref/doc/uid/TP40007126-CH3-SW18 – JeremyP
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];
Hope, to pomoże ...
+0
Nie mogę dodać bloku kodu ... proszę dodać blok kodu dodawania .. – Nit
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;
}
2
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];
0
Swift 3,0
let location1 = CLLocation(latitude: <CLLocationDegrees>, longitude: <CLLocationDegrees>)
let location2 = CLLocation(latitude: <CLLocationDegrees>, longitude: <CLLocationDegrees>)
let distance = location1.distance(from: location2)
distance
jest w metrach jako Double
https://developer.apple.com/reference/corelocation/cllocation/1423689-distance
Żartujesz? [Odwołanie do CLLocation] (http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html) Cmd-F, "meters": "Wysokość mierzona w metrach" Cmd -G: "Promień niepewności mierzony w metrach" Ponownie: "Prędkość chwilowa w metrach na sekundę" Ponownie: "Dokładność wartości wysokości w metrach." Jeszcze raz: "distanceFromLocation: Zwraca odległość (w metrach) od położenia odbiornika do określonej lokalizacji." Święta krowa! Jest to jeszcze prostsze w samym Xcode. –
Dziękuję, moje złe. –