Conforms to | |
Framework | /System/Library/Frameworks/MapKit.framework |
Availability | Available in iOS 3.0 and later. |
Declared in | MKMapView.h |
The MKMapViewDelegate
protocol defines a set of optional methods that you can use to receive map-related update messages. Because many map operations require the MKMapView
class to load data asynchronously, the map view calls these methods to notify your application when specific operations complete. The map view also uses these methods to request annotation and overlay views and to manage interactions with those views.
Important: The MapKit framework uses Google services to provide map data. Use of this protocol and the associated interfaces binds you to the Google Maps/Google Earth API terms of service. You can find these terms of service at http://code.google.com/apis/maps/iphone/terms.html.
– mapViewWillStartLocatingUser:
– mapViewDidStopLocatingUser:
– mapView:didUpdateUserLocation:
– mapView:didFailToLocateUserWithError:
– mapView:viewForAnnotation:
– mapView:didAddAnnotationViews:
– mapView:annotationView:calloutAccessoryControlTapped:
Tells the delegate that the user tapped one of the annotation view’s accessory buttons.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
The map view containing the specified annotation view.
The annotation view whose button was tapped.
The control that was tapped.
Accessory views contain custom content and are positioned on either side of the annotation title text. If a view you specify is a descendant of the UIControl
class, the map view calls this method as a convenience whenever the user taps your view. You can use this method to respond to taps and perform any actions associated with that control. For example, if your control displayed additional information about the annotation, you could use this method to present a modal panel with that information.
If your custom accessory views are not descendants of the UIControl
class, the map view does not call this method.
MKMapView.h
Tells the delegate that the drag state of one of its annotation views changed.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
The map view containing the annotation view.
The annotation view whose drag state changed.
The new drag state of the annotation view.
The previous drag state of the annotation view.
The drag state typically changes in response to user interactions with the annotation view. However, the annotation view itself is responsible for changing that state as well.
MKMapView.h
Tells the delegate that one or more annotation views were added to the map.
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
The map view that added the annotation views.
An array of MKAnnotationView
objects representing the views that were added.
By the time this method is called, the specified views are already added to the map.
MKMapView.h
Tells the delegate that one or more overlay views were added to the map.
- (void)mapView:(MKMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews
The map view that added the overlay views.
An array of MKOverlayView
objects representing the views that were added.
By the time this method is called, the specified views are already added to the map.
MKMapView.h
Tells the delegate that one of its annotation views was deselected.
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
The map view containing the annotation view.
The annotation view that was deselected.
You can use this method to track changes in the selection state of annotation views.
MKMapView.h
Tells the delegate that an attempt to locate the user’s position failed.
- (void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error
The map view that is tracking the user’s location.
An error object containing the reason why location tracking failed.
MKMapView.h
Tells the delegate that one of its annotation views was selected.
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
The map view containing the annotation view.
The annotation view that was selected.
You can use this method to track changes in the selection state of annotation views.
MKMapView.h
Tells the delegate that the location of the user was updated.
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
The map view that is tracking the user’s location.
The location object representing the user’s latest location.
While the showsUserLocation
property is set to YES
, this method is called whenever a new location update is received by the map view.
MKMapView.h
Tells the delegate that the region displayed by the map view just changed.
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
The map view whose visible region changed.
If YES
, the change to the new region was animated.
This method is called whenever the currently displayed map region changes. During scrolling, this method may be called many times to report updates to the map position. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting scrolling performance.
MKMapView.h
Tells the delegate that the region displayed by the map view is about to change.
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
The map view whose visible region is about to change.
If YES
, the change to the new region will be animated. If NO
, the change will be made immediately.
This method is called whenever the currently displayed map region changes. During scrolling, this method may be called many times to report updates to the map position. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting scrolling performance.
MKMapView.h
Returns the view associated with the specified annotation object.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
The map view that requested the annotation view.
The object representing the annotation that is about to be displayed. In addition to your custom annotations, this object could be an MKUserLocation
object representing the user’s current location.
The annotation view to display for the specified annotation or nil
if you want to display a standard annotation view.
Rather than create a new view each time this method is called, you should use the dequeueReusableAnnotationViewWithIdentifier:
method of the MKMapView
class to see if an existing annotation view of the desired type already exists. If one does exist, you should update the view to reflect the attributes of the specified annotation and return it. If a view of the appropriate type does not exist, you should create one, configure it with the needed annotation data, and return it.
If the object in the annotation parameter is an instance of the MKUserLocation
class, you can provide a custom view to denote the user’s location. To display the user’s location using the default system view, return nil
.
If you do not implement this method, or if you return nil
from your implementation for annotations other than the user location annotation, the map view uses a standard pin annotation view.
MKMapView.h
Asks the delegate for the overlay view to use when displaying the specified overlay object.
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
The map view that requested the overlay view.
The object representing the overlay that is about to be displayed.
The view to use when presenting the specified overlay on the map. If you return nil
, no view is displayed for the specified overlay object.
If you support the presentation of overlays, you must implement this method and provide the views for your overlay objects.
MKMapView.h
Tells the delegate that the specified view was unable to load the map data.
- (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error
The map view that started the load operation.
The reason that the map data could not be loaded.
This method might be called in situations where the device does not have access to the network or is unable to load the map data for some reason. It may also be called if a request for additional map tiles comes in while a previous request for tiles is still pending. You can use this message to notify the user that the map data is unavailable.
MKMapView.h
Tells the delegate that the specified map view successfully loaded the needed map data.
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
The map view that started the load operation.
This method is called when all map tiles in the currently visible area have been loaded.
MKMapView.h
Tells the delegate that the map view stopped tracking the user’s location.
- (void)mapViewDidStopLocatingUser:(MKMapView *)mapView
The map view that stopped tracking the user’s location.
This method is called when the value of the showsUserLocation
property changes to NO
.
MKMapView.h
Tells the delegate that the specified map view is about to retrieve some map data.
- (void)mapViewWillStartLoadingMap:(MKMapView *)mapView
The map view that began loading the data.
This method is called whenever a new group of map tiles need to be downloaded from the server. This typically occurs whenever you expose portions of the map by panning or zooming the content. You can use this method to mark the time that it takes for the map view to load the data.
MKMapView.h
Tells the delegate that the map view will start tracking the user’s position.
- (void)mapViewWillStartLocatingUser:(MKMapView *)mapView
The map view that is tracking the user’s location.
This method is called when the value of the showsUserLocation
property changes to YES
.
MKMapView.h
Last updated: 2010-05-11