开发者

Mapkit UserLocation found event

开发者 https://www.devze.com 2022-12-11 18:16 出处:网络
Is there an event that gets fired w开发者_JS百科hen a users location is successfully found in the iPhone mapkit?

Is there an event that gets fired w开发者_JS百科hen 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消