开发者

zoom level and annotation on MKMapView with MKPolyLine

开发者 https://www.devze.com 2023-02-16 14:50 出处:网络
I have 3 MKPolyLine that is drawn on the MKMapView. How do I zoom to the best maximum possible showing those three routes?

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号