问题
Is there an event that gets fired when a users location is successfully found in the iPhone mapkit?
I want to call a web service at the time the current location pin is dropped onto the map.
回答1:
You'll need to create CLLocationManger object and call startUpdatingLocation
method. Once the location is found and updated, CLLocationMangerDelegate method
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
will be called automatically. You can re-implement this method and call your web service from here.
回答2:
In the event that you have the MKMapView
itself displaying the user's location (either programmatically with "mapView.showsUserLocation = YES;
" or with IB checking "shows user location"), then the map view will call viewForAnnotation
when the pin is dropped. You can use:
- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:MKUserLocation.class]) {
// Call web service here
return nil;
}
}
Returning nil tells the map view to use its default pin for the user location (Blue dot with animation).
Don't forget to set your controller to be the MKMapViewDelegate
.
来源:https://stackoverflow.com/questions/1764019/mapkit-userlocation-found-event