基本上,我需要能够移动地图以显示区域(因此设置缩放),但我也不想在调用[mapVIEw setRegion:]时旋转地图.
[mapVIEw setCenterCoordinate:]运行良好,但不允许我更改缩放级别.
在iOS 7中,我使用[mapVIEw setCamera:],其中我有一个具有中心坐标和指定缩放级别的相机……我在iOS 6中基本上需要此功能.
有任何想法吗?谢谢!
解决方法 我有这个完全相同的问题,并最终完全放弃[mapVIEw setRegion:]方法,支持[mapVIEw setCamera:]使用原始区域和标题作为如何定向相机的基础.MKCoordinateRegion currentRegion = MKCoordinateRegionMake(center,span);double altitude = [self determineAltitudeForMapRect:MKMapRectForCoordinateRegion(currentRegion) withheading:_heading anDWithVIEwport:[[UIScreen mainScreen] bounds].size];MKMapCamera *currentCamera = [MKMapCamera new];[currentCamera setheading:_heading];[currentCamera setCenterCoordinate:center];[currentCamera setAltitude:altitude];[_mapVIEw setCamera:currentCamera];
这个选项的技巧是如何确定[currentCamera setAltitude:]值,这通常是使用[mapVIEw setRegion:]自动设置的
我的解决方案是改编这个答案https://stackoverflow.com/a/21034410/1130983,它使用一些简单的触发来确定高度,假设地图camara有大约30度的视角.但是,我没有传入多边形,而是直接传入MKMapRect:
- (double)determineAltitudeForMapRect:(MKMapRect)boundingRect withheading:(double)heading anDWithVIEwport:(CGSize)vIEwport{ // Get a bounding rectangle that encompasses the polygon and represents its // true aspect ratio based on the understanding of its heading. MKCoordinateRegion boundingRectRegion = MKCoordinateRegionForMapRect(boundingRect); // Calculate a new bounding rectangle that is corrected for the aspect ratio // of the vIEwport/camera -- this will be needed to ensure the resulting // altitude actually fits the polygon in vIEw for the observer. CLLocationCoordinate2D upperleftCoord = CLLocationCoordinate2DMake(boundingRectRegion.center.latitude + boundingRectRegion.span.latitudeDelta / 2,boundingRectRegion.center.longitude - boundingRectRegion.span.longitudeDelta / 2); CLLocationCoordinate2D upperRightCoord = CLLocationCoordinate2DMake(boundingRectRegion.center.latitude + boundingRectRegion.span.latitudeDelta / 2,boundingRectRegion.center.longitude + boundingRectRegion.span.longitudeDelta / 2); CLLocationCoordinate2D lowerleftCoord = CLLocationCoordinate2DMake(boundingRectRegion.center.latitude - boundingRectRegion.span.latitudeDelta / 2,boundingRectRegion.center.longitude - boundingRectRegion.span.longitudeDelta / 2); CLLocationdistance hdist = MKMetersBetweenMapPoints(MKMapPointForCoordinate(upperleftCoord),MKMapPointForCoordinate(upperRightCoord)); CLLocationdistance vdist = MKMetersBetweenMapPoints(MKMapPointForCoordinate(upperleftCoord),MKMapPointForCoordinate(lowerleftCoord)); double adjacent; if (boundingRect.size.height > boundingRect.size.wIDth) { adjacent = vdist / 2; } else { adjacent = hdist / 2; } double result = adjacent / tan(degrees_TO_radians(15)); return result;}总结
以上是内存溢出为你收集整理的iOS 6 MkMapView在更改区域时保留旋转全部内容,希望文章能够帮你解决iOS 6 MkMapView在更改区域时保留旋转所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)