zoom level and annotation on MKMapView with MKPolyLine
I have 3 MKPolyLine that is drawn on the MKMapView. How do I zoom to the best maximum possible showing those three routes? I know that I have to use the setRegi开发者_如何学Pythonon method. However I am confused on how to calculate the MKCoordinateRegion and the MKCoordinateSpan. Can someone help me out? Thanks
Also another question is how can I show an annotation at the middle of the MKPolyLine (i.e: the middle of the route)??
I would do the following:
- Find the maximum and minimum latitude and longitude values in all of your polylines. Then do:
CLLocationDegrees deltaLat = maxLat-minLat;
CLLocationDegrees deltaLong = maxLong-minLong;
CLLocationCoordinate2D centerCoord = CLLocationCoordinate2DMake(deltaLat/2, deltaLong/2);
MKCoordinateSpan span = MKCoordinateSpanMake(deltaLat, deltaLong);
MKCoordinateRegion region = MKCoordinateRegionMake(centerCoord, span);
[mapView setRegion : region animated : YES];
精彩评论