2010-04-06 50 views
2

我想整合使用地图套件在iPhone的地图,我成功的在那,但现在这是我现在面临的问题是地图集成

我有2个位置的坐标,LOCATION1和LOCATION2,现在我希望在地图上显示这两点,但我希望它们在1次时都出现在屏幕上,意味着如果它们非常远,则缩放级别会进入该点,并在地图上显示这两点,如果它们是靠近彼此,然后缩放级别显示从那个天使(我的意思是非常接近)。

现在我知道,使用经度增量和纬度增量我可以解决这个问题,但我不能找到一种方法,使之充满活力,让我没有硬编码delta值

任何帮助表示赞赏。 谢谢

回答

2
CLLocationCoordinate2D centerCoordinate; 
centerCoordinate.latitude = (location1.latitude + location2.latitude)/2; 
centerCoordinate.longitude = (location1.longitude + location2.longitude)/2; 

MKCoordinateSpan span; 
span.latitudeDelta = ABS(location1.latitude - location2.latitude); 
span.longitudeDelta = ABS(location1.longitude - location2.longitude); 

[mapView setRegion:[mapView regionThatFits:MKCoordinateRegionMake(centerCoordinate, span)] 
      animated:YES]; 
+0

非常感谢你亲爱的 – 2010-04-06 11:22:33