如何用 iPhone 制作指南针?
在谷歌上进行一番搜索后,我问自己:
是否可以用以下方法构建一个指南针(简单地显示标题/方向) iPhone 3G 的 GPS 传感器?
我怀疑,这只有在设备移动时才有可能。
任何想法表示赞赏。
After some searching on Google, I ask myself:
Is it possible to build a compass (simple showing the heading/direction) with
the iPhone 3G's GPS sensor?
I have the suspicion, that this is only possible, if the device is moving.
Any ideas are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
对于初代 iPhone 和 iPhone 3G,没有。
iPhone 3GS 于 2009 年 6 月上市,是的。 它包括一个磁力计,可用于指南针应用。
核心位置框架 在 CLHeading 类。 您可以检查设备是否支持 使用
磁力计
键可实现此功能。正如其他人所说,使用 iPhone 3G,您可以在手机移动时判断手机的移动方向,但无法判断手机的方向以向用户指示方向。 当然,可以指示用户以某种方式定向手机,结合运动可以准确地指示方向。
With the original iPhone and iPhone 3G, no.
With the iPhone 3GS available June 2009, yes. It includes a magnetometer which would allow for a compass application.
The Core Location Framework provides this information in the CLHeading class. You can check if the device supports this function with the
magnetometer
key.As others have said, with the iPhone 3G you would be able to tell the direction of movement when the phone is moving, but you would not be able to tell the orientation of the phone to indicate direction to the user. Certainly the user can be instructed to orient the phone in a certain manner which combined with the movement could indicate direction accurately.
是的,你说得对,这是唯一的办法。 虽然我认为一旦你知道了方向,你就可以通过加速度传感器跟踪手机的微小运动,并准确地绘制方向,即使原始运动停止了。
注意:这是过时的信息,在 3G 出现之前它是正确的。 不幸的是,我无法删除已接受的答案,所以请看下面。
Yes, you are right, that's the only way. Although I think once you know the direction, you could track small movements of the phone from acceleration sensors and draw the direction accurately even if the original movement stops.
Note: This is outdated info, it was correct up until 3Gs came out. Unfortunately I can't delete accepted answer so just look below.
作为对此的更新,iPhone 3GS 确实包含了一个可供应用程序使用的实际可用的数字指南针。 它使得编写这样的应用程序变得微不足道。
请参阅
CLHeading
类和MagneticHeading
属性。http://developer.apple.com/ iphone/library/documentation/CoreLocation/Reference/CLHeading_Class/Reference/Reference.html
假设手机有时间进行地理位置定位,您还可以获得真正的北向方向。
As an update to this, the iPhone 3GS does include an actual, working digital compass that is available to apps. It makes writing such an app trivial.
See the
CLHeading
class and themagneticHeading
property.http://developer.apple.com/iphone/library/documentation/CoreLocation/Reference/CLHeading_Class/Reference/Reference.html
You can also get a true north heading, assuming that the phone has had time to locate itself geographically.
通过扫描可用的应用程序,我得出的结论是,有两种方法可以为当前的 iPhone 3G 制作指南针。
By scanning the available applications I've come to the conclusion that there are two ways to make a compass for the current iPhone 3G.
您只需要实现位置管理器功能即可找到 iPhone 指向的确切方向。
所以,你可以检查这个:
CLLocationManager *locationManager;
[locationManager startUpdatingHeading];
每当你调用 startUpdatingHeading() 时,它都会调用
“- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading”方法,您需要从位置管理器覆盖该方法。
就是这样,您可以通过 newHeading.magicHeading 或 newHeading.trueHeading 找到 iPhone 3GS 指向的方向。
您会惊讶地发现,您可以获得与磁罗盘为您提供的方向完全相同的方向。
You just need to implement location manager functionality to find the exact direction in which your iPhone is pointing.
So, You can check this :
CLLocationManager *locationManager;
[locationManager startUpdatingHeading];
And whenever you call startUpdatingHeading() it will call
"- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading" method which you need to override from Location manager.
And that's it you can find the direction in which iPhone 3GS is pointing by newHeading.magneticHeading or newHeading.trueHeading.
You will surprise that you can get exact the same direction what magnetic compass gives you.
指南针只会显示您移动的方向。 它不会告诉您 iPhone 所在的方向。因此,即使使用加速计来跟踪 iPhone 已转动/移动,也不一定能让您在显示屏上指向北方。
(也就是说,你不会知道它是否在横向移动,或者我们是否将 iPhone 倒置或其他什么。你只会知道你在移动......)
2010 年 12 月编辑:
自这篇原创文章撰写以来,iPhone 3GS(09 年夏季推出)和较新的型号都配备了电子罗盘。 该指南针可以在不移动时显示正确的方向...(这意味着无论 iPhone 握持或移动的方向如何,指南针现在都能够指向北方。)
The compass will only show the direction you're moving. It will not tell you the direction the iPhone is positioned in. So even using the accelerometer to track that the iPhone has turned/moved will not necessarily let you point to north on the display.
(Ie. you won't know if its moving sideways or if we're holding the iPhone upside-down or anything. You'll just know where you're moving...)
EDIT december 2010:
Since this original post was written, the iPhone 3GS (launched summer '09) and newer models have an electronic compass. This compass can show the correct direction when without moving... (This means that the compass now is able to point to north regardless of the direction the iPhone is held or is moving.)
我认为你的怀疑是对的,GPS 位置是一个没有任何方向信息的点。 要确定方向,您需要两个点来创建方向向量。 汽车导航系统的工作原理相同。 如果汽车正在移动,它们只能显示方向矢量。
I think your right with your suspicion, a GPS position is a single point without any direction information. To determine a direction you need two points to create a direction vector. Car navigation systems work the same way. They can only show a direction vector if the car is moving.
如果您实现模拟时钟,则可以使用以下说明来叠加罗盘表盘。
这可用于“校准”指南针,并在手机移动时使用加速度计保持指向北方。
显然这不是超级准确......“高科技问题的低技术解决方案”
(指令取自http://www.qwerty.co.za)
在北半球将手表放在水平地面上,将时针指向太阳。 南北线又是将时针和 12 点钟线之间的角度分成两半的线。
在南半球,将手表放在平坦的地面上,
将数字 12 指向太阳。 南北线是将时针和 12 点钟线之间的角度分成两半的线。
If you implement an analogue clock, you can use the instructions below to superimpose a compass dial.
This could be used to 'calibrate' the compass and use the accelerometer remain pointing to North when the phone moves.
Obviously this is not super accurate... "low tech solution to a high tech problem"
(instruction taken from http://www.qwerty.co.za)
In the northern hemisphere place the watch on a level piece of ground, point the hour hand in the direction of the sun. The North-South line is again the line dividing the angle between the hour hand and the 12 o'clock line in half.
In the Southern hemisphere, place the watch on a level piece of ground,
point the figure 12 towards the sun. The North-South line is the line dividing the angle between the hour hand and the 12 o'clock line in half.
顺便说一句,iPhone 中的加速计不跟踪旋转,仅跟踪平移,因此您无法对位置和方向进行正确的 6 轴惯性跟踪。
As a side note, the accelerometers in the iphone don't track rotations only translations so you can't do proper 6 axis inertial tracking of position and direction.