I am new to swift (iOS programming in general) and am trying to figure out how to zoom a map out to fit 2 points on the map.
Currently I have
var zoomRect = MKMapRectNull;
var myLocationPointRect = MKMapRectMake(myLocation.longitude, myLocation.latitude, 0, 0)
var currentDestinationPointRect = MKMapRectMake(currentDestination.longitude, currentDestination.latitude, 0, 0)
zoomRect = myLocationPointRect;
zoomRect = MKMapRectUnion(zoomRect, currentDestinationPointRect);
Which does nothing.
Do I have to apply zoomRect
to the map somehow?
MKMapRectMake
accepts parameters of typeMKMapPoint
which are units that are not the same as latitude and longitude degrees (CLLocationDegrees
). Even though both are doubles, they are not in the same units. To convert fromCLLocationCoordinate2D
toMKMapPoint
, use theMKMapPointForCoordinate
function. But if you use theshowAnnotations
method, you don't need to do this conversion or create anMKMapRect
manually. – Starr