Skip to main content

Events

Contents

The Maps SDK provides several ways to listen and act upon events fired by the map. The generic listeners are mentioned below. However, you may also find specific callbacks exist for specific APIs or uses.

Map click events

The Maps SDK provides a set of built-in gesture recognizers. You can customize or supplement these gestures according to your use case. You can see which gesture recognizers are on your TMGLMapView by accessing the gestureRecognizers property on your map.

func addSingleTapGestureRecognizer() {
            // add a single tag gesture recognizer
            let singleTap = UITapGestureRecognizer(target: self, action: #selector(handleMapTap(sender:)))
            for recognizer in mapView.gestureRecognizers! where recognizer is UITapGestureRecognizer {
                singleTap.require(toFail: recognizer)
            }
            mapView.addGestureRecognizer(singleTap)
        }

@objc @IBAction func handleMapTap(sender: UITapGestureRecognizer) {
            // Convert tap location (CGPoint) to geographic coordinate (CLLocationCoordinate2D).
            let tapPoint: CGPoint = sender.location(in: mapView)
            let tapCoordinate: CLLocationCoordinate2D = mapView.convert(tapPoint, toCoordinateFrom: mapView)
            print("You tapped at: \(tapCoordinate.latitude), \(tapCoordinate.longitude)")
        }

Map change events

While building or changing the map, the MapView object goes through many phases. The TMGLMapViewDelegate protocol defines a set of optional methods that you can use to receive map-related update messages, allowing you to capture when a specific map event has triggered. For example:

        func mapViewDidFinishLoadingMap(_ mapView: TMGLMapView) {
            // The map finished loading
        }

There are a variety of other events available that are used in a similar manner to the above:

MethodDescription
mapViewWillStartLoadingMapMap about to start loading a new style.
mapViewWillStartRenderingFrameMap is about to start rendering a frame.
mapViewDidFinishRenderingFrameMap finished rendering the frame.
didFinishLoadingStyleStyle finished loading.

Camera change events

The map’s camera is used to define how the map is viewed; zoom level, rotation, etc. Go here for more details on the Camera itself. There are a few callbacks that you can listen to that relate to some of the camera’s movements, usually related around the beginning and end of a camera movement.

MethodDescription
regionWillChangeAnimatedThe currently displayed map camera is about to change.
mapViewRegionIsChangingThe currently displayed map camera is changing.
regionDidChangeAnimatedThe currently displayed map camera finished changing.

Movement events

Separately from the camera movement events, there is also a callback that is fired after the user moves the map.

MethodDescription
didChangeUserTrackingModeThis method is called after the map view asynchronously changes to reflect the new user tracking mode, for example by beginning to zoom or rotate.
Last updated December 1, 2022.
Contents