Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a compass with the iPhone?

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.

like image 240
Stefan Avatar asked May 07 '09 11:05

Stefan


People also ask

Can an iPhone act as a compass?

The Compass app shows you the direction iPhone is pointing, your current location, and elevation. Note: Your coordinates and elevation may not be available in certain countries or regions.

How do I get the True North compass on my iPhone?

Once the compass has been calibrated, the compass at 0 degrees will point to magnetic north — this differs from True North. If you want your iPhone's compass to always point to True North, you can change it by going to Settings > Compass > "Use True North."

Is iPhone Compass a real compass?

Compass gives accurate readings of both true north and magnetic north, and both are valid indications. True north, which is a GPS bearing linked to the geographical location of the North Pole, works when Location Services is turned on.


4 Answers

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.

like image 183
g . Avatar answered Oct 07 '22 07:10

g .


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.

like image 31
vava Avatar answered Oct 07 '22 05:10

vava


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.

like image 23
Brandon Yarbrough Avatar answered Oct 07 '22 06:10

Brandon Yarbrough


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.
like image 25
Darron Avatar answered Oct 07 '22 05:10

Darron