tags:

views:

433

answers:

2

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  A: 

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.

Mithin
+2  A: 

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.

ScottL