Programmatically move to a pin in MKMap

I am plotting a few locations on a map. After all of the locations have a pin I want to move the map and center on the first location. I tried the code below but nothing happens. What am I missing? myLocation has the coordinate I want to move to....


self.MapView.setCenterCoordinate(myLocation, animated: true)


thanks...

It's been a while since I played with MKMapView. With that caveat


     // Only one point on the map at a time in this example

     var mapPoint: MKPointAnnotation?


     mapView.setCenterCoordinate(center, animated: false)
     removeMapPoint()
     mapPoint = MKPointAnnotation()
     if let point = mapPoint {
         point.coordinate = center;
         mapView.addAnnotation(point)
     }


That's from something I was working on back in the Swift 1.1 days -- might not be correct today. Change the animated value to suit your needs. You may not want the call to `removeMapPoint` which in my case removed any previous annotation. That code is


   func removeMapPoint() {
        if mapPoint {
            mapView.removeAnnotation(mapPoint)
            mapPoint = nil
        }
    }

How do I move the map to certain point? Let say I have point A, B, C, X, Z. After I plot each point I want to center around point A.


thanks again....

That line of code looks correct in isolation. You'll need to verify that self.MapView is indeed the instance that is being displayed on screen (not one you created yourself in code but didn't add to the view hierarchy), and that the map view is laid out correctly (frame is something reasonable).

I tried the code but it has no effect. The map does not move? Is there something else I need to actually center the map?


thanks..

Programmatically move to a pin in MKMap
 
 
Q