1

I have one class that has all the MapKit functions and another class where I call the MapKit. My goal is to give an address (String) and the map show a placemark with zoom to that location.

So far I managed to get the map working and the placemark is in the right street, but dont zoom to the placemark location.

Map is declared like: @IBOutlet var mapPreview: MKMapView!

Here is the code of the placemark. How can I zoom to that placemark?

    var address = restaurante.rua + " " + restaurante.numero + "," + restaurante.localidade + ", Portugal"
    var geocoder = CLGeocoder()
    geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
        if let placemark = placemarks?[0] as? CLPlacemark {
            self.mapPreview.addAnnotation(MKPlacemark(placemark: placemark))
Renato Pimpão
  • 271
  • 3
  • 17
  • possible duplicate of [iOS MKMapView zoom to show all markers](http://stackoverflow.com/questions/3434020/ios-mkmapview-zoom-to-show-all-markers) – Shamas S Aug 29 '15 at 18:18
  • Nope. Quote from that question: "to enable zooming etc around one of the points - but that's not what I want...", but this is exactly what I want. :) – Renato Pimpão Aug 29 '15 at 18:21
  • The question has some really interesting answers. Check the function mentioned in the answer below. Hope that helps. – Shamas S Aug 29 '15 at 18:22

1 Answers1

1

I would recommend using the function

func showAnnotations(_ annotations: [AnyObject]!,
            animated animated: Bool)

Apple Documentation

Shamas S
  • 7,507
  • 10
  • 46
  • 58