MGLMapViewDelegate
@protocol MGLMapViewDelegate <NSObject>
                The MGLMapViewDelegate protocol defines a set of optional methods that you
can use to receive map-related update messages. Because many map operations
require the MGLMapView 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 information about annotations
displayed on the map, such as the styles and interaction modes to apply to
individual annotations.
- 
                  
                  
Asks the delegate whether the map view should be allowed to change from the existing camera to the new camera in response to a user gesture.
This method is called as soon as the user gesture is recognized. It is not called in response to a programmatic camera change, such as by setting the
centerCoordinateproperty or calling-flyToCamera:completionHandler:.This method is called many times during gesturing, so you should avoid performing complex or performance-intensive tasks in your implementation.
Related examples
See the Restrict map panning to an area example to learn how to use this method and
MGLMapCameraobjects to restrict a users ability to pan your map.Declaration
Objective-C
- (BOOL)mapView:(nonnull MGLMapView *)mapView shouldChangeFromCamera:(nonnull MGLMapCamera *)oldCamera toCamera:(nonnull MGLMapCamera *)newCamera;Swift
optional func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera) -> BoolParameters
mapViewThe map view that the user is manipulating.
oldCameraThe camera representing the viewpoint at the moment the gesture is recognized. If this method returns
NO, the map view’s camera continues to be this camera.newCameraThe expected camera after the gesture completes. If this method returns
YES, this camera becomes the map view’s camera.Return Value
A Boolean value indicating whether the map view should stay at
oldCameraor change tonewCamera. - 
                  
                  
Tells the delegate that the viewpoint depicted by the map view is about to change.
This method is called whenever the currently displayed map camera will start changing for any reason.
Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView regionWillChangeAnimated:(BOOL)animated;Swift
optional func mapView(_ mapView: MGLMapView, regionWillChangeAnimated animated: Bool)Parameters
mapViewThe map view whose viewpoint will change.
animatedWhether the change will cause an animated effect on the map.
 - 
                  
                  
Tells the delegate that the viewpoint depicted by the map view is changing.
This method is called as the currently displayed map camera changes as part of an animation, whether due to a user gesture or due to a call to a method such as
-[MGLMapView setCamera:animated:]. This method can be called before-mapViewDidFinishLoadingMap:is called.During the animation, this method may be called many times to report updates to the viewpoint. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting performance.
Related examples
See the Cluster point data example to learn how to trigger an action whenever the map region changes.
Declaration
Objective-C
- (void)mapViewRegionIsChanging:(nonnull MGLMapView *)mapView;Swift
optional func mapViewRegionIsChanging(_ mapView: MGLMapView)Parameters
mapViewThe map view whose viewpoint is changing.
 - 
                  
                  
Tells the delegate that the viewpoint depicted by the map view has finished changing.
This method is called whenever the currently displayed map camera has finished changing, after any calls to
-mapViewRegionIsChanging:due to animation. Therefore, this method can be called before-mapViewDidFinishLoadingMap:is called.Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated;Swift
optional func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool)Parameters
mapViewThe map view whose viewpoint has changed.
animatedWhether the change caused an animated effect on the map.
 
- 
                  
                  
Tells the delegate that the map view will begin to load.
This method is called whenever the map view starts loading, including when a new style has been set and the map must reload.
Declaration
Objective-C
- (void)mapViewWillStartLoadingMap:(nonnull MGLMapView *)mapView;Swift
optional func mapViewWillStartLoadingMap(_ mapView: MGLMapView)Parameters
mapViewThe map view that is starting to load.
 - 
                  
                  
Tells the delegate that the map view has finished loading.
This method is called whenever the map view finishes loading, either after the initial load or after a style change has forced a reload.
Declaration
Objective-C
- (void)mapViewDidFinishLoadingMap:(nonnull MGLMapView *)mapView;Swift
optional func mapViewDidFinishLoadingMap(_ mapView: MGLMapView)Parameters
mapViewThe map view that has finished loading.
 - 
                  
                  
Tells the delegate that the map view was unable to load data needed for displaying the map.
This method may be called for a variety of reasons, including a network connection failure or a failure to fetch the style from the server. You can use the given error message to notify the user that map data is unavailable.
Declaration
Objective-C
- (void)mapViewDidFailLoadingMap:(nonnull MGLMapView *)mapView withError:(nonnull NSError *)error;Swift
optional func mapViewDidFailLoadingMap(_ mapView: MGLMapView, withError error: Error)Parameters
mapViewThe map view that is unable to load the data.
errorThe reason the data could not be loaded.
 - 
                  
                  
Tells the delegate that the map view is about to redraw.
This method is called any time the map view needs to redraw due to a change in the viewpoint or style property transition. This method may be called very frequently, even moreso than
-mapViewRegionIsChanging:. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting performance.Declaration
Objective-C
- (void)mapViewWillStartRenderingFrame:(nonnull MGLMapView *)mapView;Swift
optional func mapViewWillStartRenderingFrame(_ mapView: MGLMapView)Parameters
mapViewThe map view that is about to redraw.
 - 
                  
                  
Tells the delegate that the map view has just redrawn.
This method is called any time the map view needs to redraw due to a change in the viewpoint or style property transition. This method may be called very frequently, even moreso than
-mapViewRegionIsChanging:. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting performance.Declaration
Objective-C
- (void)mapViewDidFinishRenderingFrame:(nonnull MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered;Swift
optional func mapViewDidFinishRenderingFrame(_ mapView: MGLMapView, fullyRendered: Bool)Parameters
mapViewThe map view that has just redrawn.
 - 
                  
                  
Tells the delegate that the map view is entering an idle state, and no more drawing will be necessary until new data is loaded or there is some interaction with the map.
- No camera transitions are in progress
 - All currently requested tiles have loaded
 All fade/transition animations have completed
Declaration
Objective-C
- (void)mapViewDidBecomeIdle:(nonnull MGLMapView *)mapView;Swift
optional func mapViewDidBecomeIdle(_ mapView: MGLMapView)Parameters
mapViewThe map view that has just entered the idle state.
 - 
                  
                  
Tells the delegate that the map has just finished loading a style.
This method is called during the initialization of the map view and after any subsequent loading of a new style. This method is called between the
-mapViewWillStartRenderingMap:and-mapViewDidFinishRenderingMap:delegate methods. Changes to sources or layers of the current style do not cause this method to be called.This method is the earliest opportunity to modify the layout or appearance of the current style before the map view is displayed to the user.
Related examples
See the Dynamically style interactive points and Add multiple shapes from a single shape source examples to learn how to ensure a map’s style has loaded before modifying it at runtime.
Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didFinishLoadingStyle:(nonnull MGLStyle *)style;Swift
optional func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle)Parameters
mapViewThe map view that has just loaded a style.
styleThe style that was loaded.
 - 
                  
                  
Asks the delegate whether the map view should evict cached images.
This method is called in two scenarios: when the cumulative size of unused images exceeds the cache size or when the last tile that includes the image is removed from memory.
Declaration
Objective-C
- (BOOL)mapView:(nonnull MGLMapView *)mapView shouldRemoveStyleImage:(nonnull NSString *)imageName;Swift
optional func mapView(_ mapView: MGLMapView, shouldRemoveStyleImage imageName: String) -> BoolParameters
mapViewThe map view that is evicting the image.
imageNameThe image name that is going to be removed.
Return Value
A Boolean value indicating whether the map view should evict the cached image.
 
- 
                  
                  
Tells the delegate that the map view will begin tracking the user’s location.
This method is called when the value of the
showsUserLocationproperty changes toYES.Declaration
Objective-C
- (void)mapViewWillStartLocatingUser:(nonnull MGLMapView *)mapView;Swift
optional func mapViewWillStartLocatingUser(_ mapView: MGLMapView)Parameters
mapViewThe map view that is tracking the user’s location.
 - 
                  
                  
Tells the delegate that the map view has stopped tracking the user’s location.
This method is called when the value of the
showsUserLocationproperty changes toNO.Declaration
Objective-C
- (void)mapViewDidStopLocatingUser:(nonnull MGLMapView *)mapView;Swift
optional func mapViewDidStopLocatingUser(_ mapView: MGLMapView)Parameters
mapViewThe map view that is tracking the user’s location.
 - 
                  
                  
Asks the delegate styling options for each default user location annotation view.
This method is called many times during gesturing, so you should avoid performing complex or performance-intensive tasks in your implementation.
Declaration
Objective-C
- (nonnull MGLUserLocationAnnotationViewStyle *) mapViewStyleForDefaultUserLocationAnnotationView: (nonnull MGLMapView *)mapView;Swift
optional func mapView(styleForDefaultUserLocationAnnotationView mapView: MGLMapView) -> MGLUserLocationAnnotationViewStyleParameters
mapViewThe map view that is tracking the user’s location.
 - 
                  
                  
Tells the delegate that the location of the user was updated.
While the
showsUserLocationproperty is set toYES, this method is called whenever a new location update is received by the map view. This method is also called if the map view’s user tracking mode is set toMGLUserTrackingModeFollowWithHeadingand the heading changes, or if it is set toMGLUserTrackingModeFollowWithCourseand the course changes.This method is not called if the application is currently running in the background. If you want to receive location updates while running in the background, you must use the Core Location framework.
Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didUpdateUserLocation:(nullable MGLUserLocation *)userLocation;Swift
optional func mapView(_ mapView: MGLMapView, didUpdate userLocation: MGLUserLocation?)Parameters
mapViewThe map view that is tracking the user’s location.
userLocationThe location object representing the user’s latest location. This property may be
nil. - 
                  
                  
Tells the delegate that an attempt to locate the user’s position failed.
Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didFailToLocateUserWithError:(nonnull NSError *)error;Swift
optional func mapView(_ mapView: MGLMapView, didFailToLocateUserWithError error: Error)Parameters
mapViewThe map view that is tracking the user’s location.
errorAn error object containing the reason why location tracking failed.
 - 
                  
                  
Tells the delegate that the map view’s user tracking mode has changed.
This method is called after the map view asynchronously changes to reflect the new user tracking mode, for example by beginning to zoom or rotate.
Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated;Swift
optional func mapView(_ mapView: MGLMapView, didChange mode: MGLUserTrackingMode, animated: Bool)Parameters
mapViewThe map view that changed its tracking mode.
modeThe new tracking mode.
animatedWhether the change caused an animated effect on the map.
 - 
                  
                  
Returns a screen coordinate at which to position the user location annotation. This coordinate is relative to the map view’s origin after applying the map view’s content insets.
When unimplemented, the user location annotation is aligned within the center of the map view with respect to the content insets.
This method will override any values set by
MGLMapView.userLocationVerticalAlignmentor-[MGLMapView setUserLocationVerticalAlignment:animated:].Declaration
Objective-C
- (CGPoint)mapViewUserLocationAnchorPoint:(nonnull MGLMapView *)mapView;Swift
optional func mapViewUserLocationAnchorPoint(_ mapView: MGLMapView) -> CGPointParameters
mapViewThe map view that is tracking the user’s location.
 - 
                  
                  
Tells the delegate that the map’s location updates accuracy authorization has changed.
This method is called after the user changes location accuracy authorization when requesting location permissions or in privacy settings.
Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didChangeLocationManagerAuthorization: (nonnull id<MGLLocationManager>)manager;Swift
optional func mapView(_ mapView: MGLMapView, didChangeLocationManagerAuthorization manager: MGLLocationManager)Parameters
mapViewThe map view that changed its location accuracy authorization.
managerThe location manager reporting the update.
 
- 
                  
                  
Returns an annotation image object to mark the given point annotation object on the map.
Implement this method to mark a point annotation with a static image. If you want to mark a particular point annotation with an annotation view instead, omit this method or have it return
nilfor that annotation, then implement-mapView:viewForAnnotation:.Static annotation images use less memory and draw more quickly than annotation views. On the other hand, annotation views are compatible with UIKit, Core Animation, and other Cocoa Touch frameworks.
Related examples
See the Annotation models, Add annotation views and images, and Mark a place on the map with an image examples to learn to specify which image should be used for
MGLAnnotationobjects that have been added to your map.Declaration
Objective-C
- (nullable MGLAnnotationImage *)mapView:(nonnull MGLMapView *)mapView imageForAnnotation:(nonnull id<MGLAnnotation>)annotation;Swift
optional func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage?Parameters
mapViewThe map view that requested the annotation image.
annotationThe object representing the annotation that is about to be displayed.
Return Value
The annotation image object to display for the given annotation or
nilif you want to display the default marker image or an annotation view. - 
                  
                  
Returns the alpha value to use when rendering a shape annotation.
A value of
0.0results in a completely transparent shape. A value of1.0, the default, results in a completely opaque shape.This method sets the opacity of an entire shape, inclusive of its stroke and fill. To independently set the values for stroke or fill, specify an alpha component in the color returned by
-mapView:strokeColorForShapeAnnotation:or-mapView:fillColorForPolygonAnnotation:.Declaration
Objective-C
- (CGFloat)mapView:(nonnull MGLMapView *)mapView alphaForShapeAnnotation:(nonnull MGLShape *)annotation;Swift
optional func mapView(_ mapView: MGLMapView, alphaForShapeAnnotation annotation: MGLShape) -> CGFloatParameters
mapViewThe map view rendering the shape annotation.
annotationThe annotation being rendered.
Return Value
An alpha value between
0and1.0. - 
                  
                  
Returns the color to use when rendering the outline of a shape annotation.
The default stroke color is the map view’s tint color. If a pattern color is specified, the result is undefined.
Opacity may be set by specifying an alpha component. The default alpha value is
1.0and results in a completely opaque stroke.Related examples
See the Annotation models example to learn how to modify the outline color of an
MGLShapeobject that has been added to your map as an annotation.Declaration
Objective-C
- (nonnull UIColor *)mapView:(nonnull MGLMapView *)mapView strokeColorForShapeAnnotation:(nonnull MGLShape *)annotation;Swift
optional func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColorParameters
mapViewThe map view rendering the shape annotation.
annotationThe annotation being rendered.
Return Value
A color to use for the shape outline.
 - 
                  
                  
Returns the color to use when rendering the fill of a polygon annotation.
The default fill color is the map view’s tint color. If a pattern color is specified, the result is undefined.
Opacity may be set by specifying an alpha component. The default alpha value is
1.0and results in a completely opaque shape.Related examples
See the Add a polygon annotation example to learn how to modify the color of a an
MGLPolygonat runtime.Declaration
Objective-C
- (nonnull UIColor *)mapView:(nonnull MGLMapView *)mapView fillColorForPolygonAnnotation:(nonnull MGLPolygon *)annotation;Swift
optional func mapView(_ mapView: MGLMapView, fillColorForPolygonAnnotation annotation: MGLPolygon) -> UIColorParameters
mapViewThe map view rendering the polygon annotation.
annotationThe annotation being rendered.
Return Value
The polygon’s interior fill color.
 - 
                  
                  
Returns the line width in points to use when rendering the outline of a polyline annotation.
By default, the polyline is outlined with a line
3.0points wide.Related examples
See the Add a line annotation from GeoJSON example to learn how to modify the line width of an
MGLPolylineFeatureon your map.Declaration
Objective-C
- (CGFloat)mapView:(nonnull MGLMapView *)mapView lineWidthForPolylineAnnotation:(nonnull MGLPolyline *)annotation;Swift
optional func mapView(_ mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloatParameters
mapViewThe map view rendering the polygon annotation.
annotationThe annotation being rendered.
Return Value
A line width for the polyline, measured in points.
 
- 
                  
                  
Returns a view object to mark the given point annotation object on the map.
Implement this method to mark a point annotation with a view object. If you want to mark a particular point annotation with a static image instead, omit this method or have it return
nilfor that annotation, then implement-mapView:imageForAnnotation:instead.Annotation views are compatible with UIKit, Core Animation, and other Cocoa Touch frameworks. On the other hand, static annotation images use less memory and draw more quickly than annotation views.
The user location annotation view can also be customized via this method. When
annotationis an instance ofMGLUserLocation(or equal to the map view’suserLocationproperty), return an instance ofMGLUserLocationAnnotationView(or a subclass thereof).Related examples
See the Add annotation views and images example to learn how to specify what
MGLViewAnnotationto use for a givenMGLPointAnnotationobject on your map.Declaration
Objective-C
- (nullable MGLAnnotationView *)mapView:(nonnull MGLMapView *)mapView viewForAnnotation:(nonnull id<MGLAnnotation>)annotation;Swift
optional func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView?Parameters
mapViewThe map view that requested the annotation view.
annotationThe object representing the annotation that is about to be displayed.
Return Value
The view object to display for the given annotation or
nilif you want to display an annotation image instead. - 
                  
                  
Tells the delegate that one or more annotation views have been added and positioned on the map.
This method is called just after the views are added to the map. You can implement this method to animate the addition of the annotation views.
Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didAddAnnotationViews: (nonnull NSArray<MGLAnnotationView *> *)annotationViews;Swift
optional func mapView(_ mapView: MGLMapView, didAdd annotationViews: [MGLAnnotationView])Parameters
mapViewThe map view to which the annotation views were added.
annotationViewsAn array of
MGLAnnotationViewobjects representing the views that were added. 
- 
                  
                  
Returns a Boolean value indicating whether the shape annotation can be selected.
If the return value is
YES, the user can select the annotation by tapping on it. If the delegate does not implement this method, the default value isYES.Declaration
Objective-C
- (BOOL)mapView:(nonnull MGLMapView *)mapView shapeAnnotationIsEnabled:(nonnull MGLShape *)annotation;Swift
optional func mapView(_ mapView: MGLMapView, shapeAnnotationIsEnabled annotation: MGLShape) -> BoolParameters
mapViewThe map view that has selected the annotation.
annotationThe object representing the shape annotation.
Return Value
A Boolean value indicating whether the annotation can be selected.
 - 
                  
                  
Tells the delegate that one of its annotations was selected.
You can use this method to track changes in the selection state of annotations.
If the annotation is associated with an annotation view, you can also implement
-mapView:didSelectAnnotationView:, which is called immediately after this method is called.Related examples
See the Dynamically style interactive points example to learn how to remove an annotation view if it has already been selected.
Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didSelectAnnotation:(nonnull id<MGLAnnotation>)annotation;Swift
optional func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation)Parameters
mapViewThe map view containing the annotation.
annotationThe annotation that was selected.
 - 
                  
                  
Tells the delegate that one of its annotations was deselected.
You can use this method to track changes in the selection state of annotations.
If the annotation is associated with an annotation view, you can also implement
-mapView:didDeselectAnnotationView:, which is called immediately after this method is called.Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didDeselectAnnotation:(nonnull id<MGLAnnotation>)annotation;Swift
optional func mapView(_ mapView: MGLMapView, didDeselect annotation: MGLAnnotation)Parameters
mapViewThe map view containing the annotation.
annotationThe annotation that was deselected.
 - 
                  
                  
Tells the delegate that one of its annotation views was selected.
You can use this method to track changes in the selection state of annotation views.
This method is only called for annotation views. To track changes in the selection state of all annotations, including those associated with static annotation images, implement
-mapView:didSelectAnnotation:, which is called immediately before this method is called.Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didSelectAnnotationView:(nonnull MGLAnnotationView *)annotationView;Swift
optional func mapView(_ mapView: MGLMapView, didSelect annotationView: MGLAnnotationView)Parameters
mapViewThe map view containing the annotation.
annotationViewThe annotation view that was selected.
 - 
                  
                  
Tells the delegate that one of its annotation views was deselected.
You can use this method to track changes in the selection state of annotation views.
This method is only called for annotation views. To track changes in the selection state of all annotations, including those associated with static annotation images, implement
-mapView:didDeselectAnnotation:, which is called immediately before this method is called.Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView didDeselectAnnotationView:(nonnull MGLAnnotationView *)annotationView;Swift
optional func mapView(_ mapView: MGLMapView, didDeselect annotationView: MGLAnnotationView)Parameters
mapViewThe map view containing the annotation.
annotationViewThe annotation view that was deselected.
 
- 
                  
                  
Returns a Boolean value indicating whether the annotation is able to display extra information in a callout bubble.
This method is called after an annotation is selected, before any callout is displayed for the annotation.
If the return value is
YES, a callout view is shown when the user taps on an annotation, selecting it. The default callout displays the annotation’s title and subtitle. You can add accessory views to either end of the callout by implementing the-mapView:leftCalloutAccessoryViewForAnnotation:and-mapView:rightCalloutAccessoryViewForAnnotation:methods. You can further customize the callout’s contents by implementing the-mapView:calloutViewForAnnotation:method.If the return value is
NO, or if this method is absent from the delegate, or if the annotation lacks a title, the annotation will not show a callout even when selected.Related examples
See the Add annotation views and images, Display custom views as callouts, and Default callout usage examples to learn how to show callouts for
MGLAnnotationobjects.Declaration
Objective-C
- (BOOL)mapView:(nonnull MGLMapView *)mapView annotationCanShowCallout:(nonnull id<MGLAnnotation>)annotation;Swift
optional func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> BoolParameters
mapViewThe map view that has selected the annotation.
annotationThe object representing the annotation.
Return Value
A Boolean value indicating whether the annotation should show a callout.
 - 
                  
                  
Returns a callout view to display for the given annotation.
If this method is present in the delegate, it must return a new instance of a view dedicated to display the callout. The returned view will be configured by the map view.
If this method is absent from the delegate, or if it returns
nil, a standard, two-line, bubble-like callout view is displayed by default.Related examples
See the Display custom views as callouts example to learn how to customize an
MGLAnnotationobject’sMGLCalloutView.Declaration
Objective-C
- (nullable id<MGLCalloutView>)mapView:(nonnull MGLMapView *)mapView calloutViewForAnnotation:(nonnull id<MGLAnnotation>)annotation;Swift
optional func mapView(_ mapView: MGLMapView, calloutViewFor annotation: MGLAnnotation) -> MGLCalloutView?Parameters
mapViewThe map view that requested the callout view.
annotationThe object representing the annotation.
Return Value
A view conforming to the
MGLCalloutViewprotocol, ornilto use the default callout view. - 
                  
                  
Returns the view to display on the left side of the standard callout bubble.
The left callout view is typically used to convey information about the annotation or to link to custom information provided by your application.
If the view you specify is a descendant of the
UIControlclass, you can use the map view’s delegate to receive notifications when your control is tapped, by implementing the-mapView:annotation:calloutAccessoryControlTapped:method. If the view you specify does not descend fromUIControl, your view is responsible for handling any touch events within its bounds.If this method is absent from the delegate, or if it returns
nil, the standard callout view has no accessory view on its left side. The return value of this method is ignored if-mapView:calloutViewForAnnotation:is present in the delegate.To display a view on the callout’s right side, implement the
-mapView:rightCalloutAccessoryViewForAnnotation:method.Related examples
See the Default callout usage example to learn how to modify the view that is displayed on the left side of the standard callout bubble.
Declaration
Objective-C
- (nullable UIView *)mapView:(nonnull MGLMapView *)mapView leftCalloutAccessoryViewForAnnotation:(nonnull id<MGLAnnotation>)annotation;Swift
optional func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView?Parameters
mapViewThe map view presenting the annotation callout.
annotationThe object representing the annotation with the callout.
Return Value
The accessory view to display.
 - 
                  
                  
Returns the view to display on the right side of the standard callout bubble.
The right callout view is typically used to convey information about the annotation or to link to custom information provided by your application.
If the view you specify is a descendant of the
UIControlclass, you can use the map view’s delegate to receive notifications when your control is tapped, by implementing the-mapView:annotation:calloutAccessoryControlTapped:method. If the view you specify does not descend fromUIControl, your view is responsible for handling any touch events within its bounds.If this method is absent from the delegate, or if it returns
nil, the standard callout view has no accessory view on its right side. The return value of this method is ignored if-mapView:calloutViewForAnnotation:is present in the delegate.To display a view on the callout’s left side, implement the
-mapView:leftCalloutAccessoryViewForAnnotation:method.Related examples
See the Default callout usage example to learn how to modify the view that is displayed on the right side of the standard callout bubble.
Declaration
Objective-C
- (nullable UIView *)mapView:(nonnull MGLMapView *)mapView rightCalloutAccessoryViewForAnnotation: (nonnull id<MGLAnnotation>)annotation;Swift
optional func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView?Parameters
mapViewThe map view presenting the annotation callout.
annotationThe object representing the annotation with the callout.
Return Value
The accessory view to display.
 - 
                  
                  
Tells the delegate that the user tapped one of the accessory controls in the annotation’s callout view.
In a standard callout view, accessory views contain custom content and are positioned on either side of the annotation title text. If an accessory view you specify is a descendant of the
UIControlclass, 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 displays 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
UIControlclass, the map view does not call this method. If the annotation has a custom callout view via the-mapView:calloutViewForAnnotation:method, you can specify the custom accessory views using theMGLCalloutViewprotocol’sleftAccessoryViewandrightAccessoryViewproperties.Related examples
See the Default callout usage example to learn how to trigger an action when the standard callout bubble’s accessory control is tapped.
Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView annotation:(nonnull id<MGLAnnotation>)annotation calloutAccessoryControlTapped:(nonnull UIControl *)control;Swift
optional func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl)Parameters
mapViewThe map view containing the specified annotation.
annotationThe annotation whose accessory view was tapped.
controlThe control that was tapped.
 - 
                  
                  
Tells the delegate that the user tapped on an annotation’s callout view.
This method is called when the user taps on the body of the callout view, as opposed to the callout’s left or right accessory view. If the annotation has a custom callout view via the
-mapView:calloutViewForAnnotation:method, this method is only called whenever the callout view calls its delegate’s-[MGLCalloutViewDelegate calloutViewTapped:]method.If this method is present on the delegate, the standard callout view’s body momentarily highlights when the user taps it, whether or not this method does anything in response to the tap.
Related examples
See the Display custom views as callouts example to learn how to trigger an action when an
MGLAnnotationsMGLCalloutViewis tapped.Declaration
Objective-C
- (void)mapView:(nonnull MGLMapView *)mapView tapOnCalloutForAnnotation:(nonnull id<MGLAnnotation>)annotation;Swift
optional func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation)Parameters
mapViewThe map view containing the specified annotation.
annotationThe annotation whose callout was tapped.
 
              Install in Dash
            
        MGLMapViewDelegate Protocol Reference