我有一個用戶位置(藍點)和註釋mapView
。當選擇註釋時,我將文本設置爲distLabel
- 「距離點4.0%m的距離」。如何在用戶移動時更新該文本標籤?如何計算用戶移動時從用戶位置到註釋的距離
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]];
}
我知道有一個功能didUpdateToLocation
,但我怎麼能與didSelectAnnotationView
使用它呢?
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
//Did update to location
}
從你非常回答一如既往!謝謝! –