I have a swift
app with a MapView. These are my settings on story board for the map:
Also, in the code I'm 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 method centerMapOnLocation
centers the map initially on 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 user only to zoom in/zoom out to the exact gps coordinates.
Currently user cannot scroll the map, but he can rotate it, also - he can double tap wherever on the map and it will zoom there.
I want to disable those options and make an effect, that when user double taps the map (or pinch) - it will only zoom to the initial location.
How can I do it, and also - why does the rotateEnabled = false
doesn't work?
Add below code in double tap action 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 and mapView is MKMapView's object.
Hope this will solve your problem :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With