How to build a compass with iPhone?

After some googling, I ask myself:

Is it possible to build a compass (just showing the heading / direction) using the iPhone 3G GPS sensor?

I have a suspicion that this is only possible when moving the device.

Any ideas are welcome.

+6
iphone navigation gps magnetometer
source share
9 answers

Yes, you are right, this is the only way. Although I think that as soon as you know the direction, you can track the small movements of the phone from the acceleration sensors and accurately direct the direction, even if the original movement stops.

Note. . This is outdated information, it was correct until the 3Gs came out. Unfortunately, I cannot delete the accepted answer, so just look below.

+4
source share

With the original iPhone and iPhone 3G no.

With the iPhone 3GS, available in June 2009, yes. It includes a magnetometer that allows you to use the compass.

The Core Location Framework provides this information in CLHeading . You can check if the function is supported by the magnetometer key.

As others said, with the iPhone 3G you can specify the direction of movement when the phone is moving, but you cannot specify the orientation of the phone to indicate the direction for the user. Of course, the user can be instructed to orient the phone in a certain way, which in combination with movement can accurately indicate the direction.

+9
source share

As an update to this, the iPhone 3GS includes the actual working compass available for applications. This makes recording such an application 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 the true course to the north, assuming that the phone managed to find itself geographically.

+4
source share

Scanning the available applications, I came to the conclusion that there are two ways to make a compass for the current iPhone 3G.

  • Require the phone to move. Use the difference in GPS data to determine the direction.
  • Require the user to point the phone in the sun. Use GPS and time information to determine directions.
+2
source share

The compass displays only the direction of travel. He will not tell you the direction in which the iPhone is. Thus, even using the accelerometer to track that the iPhone has rotated / moved will not necessarily allow you to point north on the display.

(That is, you won’t know if it moves sideways or if we hold the iPhone upside down or something else. You just find out where we are moving ...)

EDIT December 2010: Since this original post was written, iPhone 3GS (early summer '09) and newer models have an electronic compass. This compass can show the right direction without moving ... (This means that the compass can now point north, regardless of the direction the iPhone is held or moving.)

+2
source share

You just need to implement the location manager functionality to find the exact direction your iPhone is pointing.

So you can check this out:

CLLocationManager * locationManager; [locationManager startUpdatingHeading];

And whenever you call startUpdatingHeading (), it calls "- (void) locationManager: (CLLocationManager *) manager didUpdateHeading: (CLHeading *) the newHeading method, which needs to be redefined from the location manager.

And that you can find the direction in which the iPhone 3GS points to newHeading.magneticHeading or newHeading.trueHeading.

You will be surprised that you can get the same direction that the magnetic compass gives you.

+2
source share

I think that your right with your suspicion, the GPS position is a single point without direction information. To determine the direction, you will need two points to create a direction vector. Car navigation systems work the same. They can only show the direction vector if the car is moving.

+1
source share

If you use an analog clock, you can use the instructions below to compose the compass.

This can be used to “calibrate” the compass, and when you move the phone, the accelerometer stays north.

Obviously, this is not super accurate ... "low-tech solution to a high-tech problem"

(instructions taken from http://www.qwerty.co.za )

In the northern hemisphere, place the clock on an even piece of land, point clockwise in the direction of the sun. The North-South line is again a line dividing the angle between the clockwise and the 12-hour line in half.

In the Southern Hemisphere, place the watch on an even piece of land, point the number 12 in the sun. The North-South line is the line dividing the angle between the clockwise and the 12-hour line in half.

+1
source share

As a side note, iphone’s accelerometers do not track rotations only transfers, so you cannot perform proper inertial tracking on the 6 axis and 6 axis.

+1
source share

All Articles