我想显示我的当前位置在地图下(iOS 6和iOS 7),根据下面的屏幕截图,用户可以看到更多的谷歌默认应用程序与谷歌地图。
现在,光标在视图中显示中心,如下图所示,我的应用程序使用苹果地图。
因此,屏幕的最大部分用于显示后面的内容,而它不能向前看很远。
在第一张图片和第二张图片中,我与谷歌导航进行了比较,谷歌导航显示的当前位置在屏幕上要低得多,旋转角度大致相同。我增加了一些箭头来说明我在说什么。
我尝试了下面的代码设置中心,因为我找不到设置较低。
mapView.userTrackingMode = MKUserTrackingModeFollow;
也尝试了下面的方法
setCenterCoordinate:currentLocation.coordinate动画mapView :是的;
发布于 2014-07-01 13:34:13
不要设置userTrackingMode
或地图的centerCoordinate
。
相反,您可以尝试将MKMapCamera
指向用户正朝着的方向略高于用户的坐标。这将自动将用户的位置放在屏幕较低的位置。
计算坐标“前面的短距离”目前还没有内置到iOS SDK中,所以您必须手动计算它。
一种方法是使用如下所示的方法:
Calculate new coordinate x meters and y degree away from one coordinate。
使用这个答案中的coordinateFromCoord:atDistanceKm:atBearingDegrees:
方法,您可以像这样设置摄像机:
MKMapCamera *cam = [MKMapCamera camera];
CLLocationCoordinate2D coordinateAhead =
[self coordinateFromCoord:currentLocation.coordinate
atDistanceKm:0.15
atBearingDegrees:currentLocation.course];
//adjust distance (0.15 km) as needed
cam.centerCoordinate = coordinateAhead;
cam.heading = currentLocation.course;
cam.pitch = 80; //adjust pitch as needed (0=look straight down)
cam.altitude = 100; //adjust as needed (meters)
[mapView setCamera:cam animated:YES];
在模拟器中尝试使用“城市自行车骑行”、“城市跑步”或“高速公路驱动器”。
您可能需要调整一些数字,以获得您想要的透视图。
发布于 2018-07-10 11:19:41
将layoutMargins
设置在MKMapView
上运行得很好。
根据医生的说法
在视图中布局内容时要使用的默认间距。 在iOS 11及更高版本中,使用directionalLayoutMargins属性指定布局边距,而不是此属性。
要将相机的中心点偏移到MKMapView
的下半部,只需将UIEdgeInsets.top
设置为MKMapView's
高度的一半即可。
class MapViewController: UIViewController {
@IBOutlet var mapView: MKMapView!
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let layoutMargins = UIEdgeInsets(top: self.mapView.bounds.size.height / 2, left: 0, bottom: 0, right: 0)
self.mapView.layoutMargins = layoutMargins
}
发布于 2014-07-01 11:52:58
一个简单的解决方法应该是使MKMapView帧比设备的屏幕更大。类似于:
MapViewHeight = (WindowHeight - desiredOffsetFromBottom)*2
https://stackoverflow.com/questions/24509112
复制相似问题