Ich habe einen Benutzerstandort (blauer Punkt) und Anmerkungen unter mapView
. Wenn Annotation ausgewählt ist, setze ich Text auf distLabel
- "Entfernung zu Punkt% 4.0f m.". Wie kann ich diese Textbeschriftung aktualisieren, wenn der Benutzer bewegt?So berechnen Sie die Entfernung vom Benutzerstandort zur Annotation, wenn sich der Benutzer bewegt
didSelectAnnotationView:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
CLLocation *pinLocation =
[[CLLocation alloc] initWithLatitude:
[(MyAnnotation*)[view annotation] coordinate].latitude
longitude:
[(MyAnnotation*)[view annotation] coordinate].longitude];
CLLocation *userLocation =
[[CLLocation alloc] initWithLatitude:
self.mapView.userLocation.coordinate.latitude
longitude:
self.mapView.userLocation.coordinate.longitude];
CLLocationDistance distance = [pinLocation distanceFromLocation:userLocation];
[distLabel setText: [NSString stringWithFormat:@"Distance to point %4.0f m.",
distance]];
}
Ich weiß, es ist eine Funktion didUpdateToLocation
, aber wie kann ich es mit didSelectAnnotationView
?
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
//Did update to location
}
Große Antwort wie von Ihnen immer! Vielen Dank! –