Is there a way to enable MKMapView scaling only in a specific region when disabling any other user interaction?

I have a swift application with MapView. These are my settings on the map bulletin board:

enter image description here

Also, in the code I am doing:

 let regionRadius: CLLocationDistance = 10000 let initialLocation = CLLocation(latitude: latitude, longitude: longitude) centerMapOnLocation(initialLocation, map: cell.mapView, radius: regionRadius) cell.mapView.scrollEnabled = false cell.mapView.rotateEnabled = false 

My centerMapOnLocation method first centers the map at a specific location:

 func centerMapOnLocation(location: CLLocation, map: MKMapView, radius: CLLocationDistance) { let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, radius * 2.0, radius * 2.0) map.setRegion(coordinateRegion, animated: true) } 

I want to allow the user to only zoom in / out to the exact gps coordinates.

Currently, the user cannot scroll the map, but he can rotate it, and also - he can double-click anywhere on the map, and he will zoom.

I want to turn off these options and make an effect when the user removes the map (or pinch) twice - it will only approach the original location.

How can I do this, and also - why does rotateEnabled = false not work?

+5
source share
1 answer

Add below code to double tap method

 var annotationPoint = MKMapPointForCoordinate(zoomToLocation.coordinate) var zoomRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1) mapView.setVisibleMapRect(zoomRect, animated: true) 

Here zoomToLocation is your desired CLLocation object, and mapView is an MKMapView object.

Hope this solves your problem :)

+3
source

Source: https://habr.com/ru/post/1258296/


All Articles