I want the location of the pin to zoom in on tapping the pin so that the location is at the center. I have no idea how to do this. Please help me.
There's a couple of things you are trying to make happen.
If you have the mapView properly initiated in your project (with the view as its delegate), then both of the above points can be done by using the mapView(_:didSelectAnnotationView:) method, like this:
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
// get the particular pin that was tapped
let pinToZoomOn = view.annotation
// optionally you can set your own boundaries of the zoom
let span = MKCoordinateSpanMake(0.5, 0.5)
// or use the current map zoom and just center the map
// let span = mapView.region.span
// now move the map
let region = MKCoordinateRegion(center: pinToZoomOn!.coordinate, span: span)
mapView.setRegion(region, animated: true)
}
This method tells the delegate (your view most probably) that one of the map annotation views was selected and to move (and or zoom) to that coordinate area.
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