Search code examples
iosswiftmglmapview

How can I detect a change in zoom level in mapbox map?


I am trying to change certain properties of a map and of things on a map when as the user zooms in or out certain distances. How can this be achieved? I have tried:

func mapView(_ mapView: MGLMapView, didChange mode: MGLUserTrackingMode, animated: Bool) {
    print(mode, "This is the mode")
    print(mapView.centerCoordinate, "This is the map view ")
}

But That did not seem to print anything inside the method when I moved around.


Solution

  • You can use the delegate method for this. mapView:regionDidChangeAnimated:

    A complete list is mentioned here.

    func mapViewRegionIsChanging(_ mapView: MGLMapView) {
        print(mapView.zoomLevel, " Cenetr -<<<<")
    }