2014-07-01 51 views
2

我想在地图(iOS 6和iOS 7)中根据以下屏幕截图显示我当前位置较低的位置,以便用户可以看到更多视图[谷歌地图的谷歌默认应用程序]。在MKMapView中设置当前位置图标的下端

enter image description here

现在,示出在视图中按照下面的图像[我与苹果地图应用]中心光标。 enter image description here

因此,屏幕的最大部分用于显示后面的内容,但它不能很远。

在第一幅图像和第二幅图像中,我比较了谷歌导航,它显示了屏幕中当前位置大大低于相同的旋转角度。我添加了一些箭头来显示我在说什么。

我尝试下面的代码设置中心,因为我找不到设置较低。

mapView.userTrackingMode = MKUserTrackingModeFollow;

并且还尝试以下方法

[MapView的setCenterCoordinate:currentLocation.coordinate动画:YES];

+0

尝试设置区域 –

回答

2

不要设置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]; 

与“城市骑自行车”试试这个,“城市运行”,或者“高速公路驱动器”中的模拟器。
您可能需要调整一些数字才能获得所需的视角。

+0

它在iOS 7中工作正常,但我可以为iOS 6做什么 –

+0

iOS 6没有内置3D支持。您必须创建自定义解决方案(或尝试使用[Google Maps SDK for iOS](https://developers.google.com/maps/documentation/ios),而不是它的GMSCameraPosition,尽管我不知道它是否支持iOS 6)。 – Anna

0

一个简单的解决方法是使MKMapView框架大于设备的屏幕。 喜欢的东西:

MapViewHeight = (WindowHeight - desiredOffsetFromBottom)*2 
+0

无法让这个在iOS8上工作 –

相关问题