我是 iOS 开发新手。我的目标是在屏幕上显示指南针。我有某个位置的纬度和经度。我已经使用 CLLocation 获取了当前的纬度和经度。
我已经使用 API 计算了两点之间的距离,但现在我想知道手机的正确方向 N/S/E/W 以及类似根据正确北极的方向...我不确定。
iPhone北极和实际北极有什么概念吗?
我想显示一条指向特定经度和纬度的线,即使我的手机正在旋转或移动;该线仅指向该点。
请帮助我,我现在应该去哪里?
任何指导或链接/图都会很棒。
I am new to iOS development. My objective is to show a compass on Screen. I have a latitude and longitude of a certain location. I have gotten my current latitude and longitude by using CLLocation.
I have calculated the distance between two points using an API, but now I want to know the correct direction of my phone N/S/E/W and something like according to correct north pole... I am not sure.
Is there some concept of iPhone north pole and actual north pole?
I want show a line pointing towards the particular longitude and latitude, even if my phone is rotating or moving; the line points towards that point only.
Please help me, where i should proceed now?
Any guidance or links/tut will be great.
发布评论
评论(1)
这称为 CLLocation 的“标题”。
请参阅CLLocationManager 文档部分为您的应用程序配置标题并调用
startUpdatingHeading
收到标题更改的通知,即当您的 iPhone 指向另一个点时。然后使用标准的 CLLocationManagerDelegate 方法来了解标题更改并相应地重新绘制线条。
请阅读位置感知编程指南,了解有关位置服务和标题的更多信息,尤其是这部分甚至包含示例代码。
PS:关于两个不同的北,没有“iPhone北极”的概念,这与iPhone本身无关。在地理系统中,需要考虑两个北参考:磁北极(根据地球磁场定义)和真北极(根据地球旋转轴定义)。
位置感知编程指南中也对此进行了详细解释(就像所有事情一样;始终阅读编程指南,这些指南通常都是很棒且非常完整的资源):
This is called the "heading" of a CLLocation.
See the CLLocationManager doc part to configure heading for you app and call
startUpdatingHeading
to be notified with your heading changes, namely when your iPhone is pointing toward another point.Then use the standard
CLLocationManagerDelegate
methods to be informed of heading changes and redraw your line accordingly.Read the Location Awareness Programming Guide for more info about Location Services and heading, especially this part that even contains sample code.
PS: About the two different north, there is no concept of "iPhone North Pole", that's nothing related the the iPhone itself. In Geographic systems, there are two north references to consider: the Magnetic North Pole, which is defined according to the earth magnetic field, and the True North Pole, which is defined according the rotational axis of the earth.
That's also explained in details in the Location Awareness Programming Guide too (like quite everything; always read Programming Guides which are great and very complete resources in general):