Objective C - iPhone zu vergleichen 2 CLLocations / GPS-Koordinaten
-
21-09-2019 - |
Frage
Ok, also dank Claus Broch habe ich einige Fortschritte mit zwei Standorten GPS vergleichen. Ich muß sagen können „IF Current gleich (jede GPS-Position aus einer Liste) dann etwas
Mein Code im Moment ist:
CLLocationCoordinate2D bonusOne;
bonusOne.latitude = 37.331689;
bonusOne.longitude = -122.030731;
Welche Simulatoren sind GPS-Position an Endlos-Schleife
CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:bonusOne.latitude longitude:bonusOne.longitude];
double distance = [loc1 getDistanceFrom:newLocation];
if(distance <= 10000000) {
tun dann etwas }
Eine beliebige Anzahl unter 10000000 und es wird davon ausgegangen, dass es keine Übereinstimmung gibt.
Lösung
Ja, können Sie getDistanceFrom
verwenden, um die Entfernung zwischen zwei Punkten zu bekommen. Der Abstand ist in Metern. Sie können diesen Vergleich nutzen, im Vergleich mit der aktuellen horizontalen Genauigkeit der Positionsmanager, um festzustellen, ob Sie in etwa auf der „Bonus einer“ Position sind.
CLLocation *bonusLocation = [[CLLocation alloc] initWithLatitude:bonusOne.latitude longitude:bonusOne.longitude];
float distance = [bonusLocation getDistanceFrom:newLocation];
float threshold = 2 * [newLocation horizontalAccuracy]; // Or whatever you like
if(distance <= threshold) {
// You are at the bonus location.
}