Mapkit UserLocation found event

限于喜欢 提交于 2020-01-24 01:20:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!