在MKMapView中设置当前位置图标的下方 [英] set current location icon lower side in MKMapView

查看:203
本文介绍了在MKMapView中设置当前位置图标的下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to show my current location lower in the map (iOS 6 and iOS 7) as per below screen shot to user can see further view [google default app with google map].

现在,在视图中显示中心的光标如下图所示[我的app with apple map]。

Right now, the cursor that shows center in the view as per below image [my app with apple map] .

因此最大的部分屏幕用于显示背后的内容,但它无法向前看。

Therefore the largest part of the screen is used to display what's behind, while it cannot look forward very far.

在第一张图片和第二张图片中,我将与Google导航进行比较,后者显示当前在屏幕中位置低得多,旋转角度大致相同。我添加了一些箭头来显示我正在谈论的内容。

In the first image and second image, I compare to Google Navigation, which shows the current position much lower in the screen, for about the same rotation angle. I've added some arrows to show what I'm talking about.

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

i tried below code for set center because i cannot find to set lower.


mapView.userTrackingMode = MKUserTrackingModeFollow;

mapView.userTrackingMode = MKUserTrackingModeFollow;

并尝试以下方法


[mapView setCenterCoordinate:currentLocation.coordinate animated:YES];

[mapView setCenterCoordinate:currentLocation.coordinate animated:YES];


推荐答案

不要设置 userTrackingMode 或地图的 centerCoordinate

相反,您可以尝试将 MKMapCamera 指向坐标略微超前用户朝着他们前进的方向。这将自动将用户的位置放在屏幕上。

Instead, you can try pointing the MKMapCamera to a coordinate slightly ahead of the user's in the direction they are heading. This will automatically put the user's location lower on the screen.

计算前方短距离的坐标当前未内置于iOS SDK中,因此您必须手动计算。

Calculating the coordinate "a short distance ahead" is not currently built into the iOS SDK so you'd have to calculate it manually.

一种方法是使用以下方法:

计算新坐标x米和远离一个坐标的y度

One way to do it is using the method shown in:
Calculate new coordinate x meters and y degree away from one coordinate.

使用 coordinateFromCoord:atDistanceKm:atBearingDegrees:该答案的方法,您可以像这样设置相机:

Using the coordinateFromCoord:atDistanceKm:atBearingDegrees: method from that answer, you could set the camera like this:

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

尝试使用City Bicycle Ride,City Run或Freeway Drive模拟器。

您可能需要调整一些数字以获得所需的视角。

Try this with the "City Bicycle Ride", "City Run", or "Freeway Drive" in the simulator.
You may need to adjust some of the numbers to get the perspective you want.

这篇关于在MKMapView中设置当前位置图标的下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆