5

I have a swift app with a MapView. These are my settings on story board for the map:

enter image description here

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?

user3766930
  • 5,629
  • 10
  • 51
  • 104

1 Answers1

3

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 :)

Steve Gear
  • 757
  • 2
  • 16
  • 44
  • hm but how can I pass the mapView to the double tap action method? Currently that map is in my tableView, so I have it in `cellForRowAt` method, and not outside :| – user3766930 Oct 18 '16 at 19:29