चलाता है तो उपयोगकर्ता स्थान से एनोटेशन तक दूरी की गणना कैसे करें मेरे पास एक उपयोगकर्ता स्थान (नीला बिंदु) और एनोटेशन mapView
पर है। जब एनोटेशन का चयन किया जाता है, तो मैं पाठ को distLabel
पर सेट करता हूं - "बिंदु% 4.0f मीटर से दूरी"। जब उपयोगकर्ता चलता है तो मैं उस टेक्स्ट लेबल को कैसे अपडेट कर सकता हूं?जब उपयोगकर्ता
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
}
महान हमेशा की तरह जवाब आप से! धन्यवाद! –