How to build a compass with the iPhone?

为君一笑 提交于 2019-12-21 12:47:33

问题


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.


回答1:


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.




回答2:


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.

  • http://www.apple.com/iphone/iphone-3g-s/maps-compass.html
  • http://www.google.com/search?q=iphone%20magnetometer

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.




回答3:


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 the magneticHeading 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.




回答4:


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.

  1. Require the phone to move. Use the difference in GPS data to determine the direction.
  2. Require the user to point the phone at the sun. Use GPS and time information to determine directions.



回答5:


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.




回答6:


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.)




回答7:


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.




回答8:


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.




回答9:


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.



来源:https://stackoverflow.com/questions/834117/how-to-build-a-compass-with-the-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!