Channels ▼


MonoTouch and the iPhone: The GPS and Compass Functions

Other Features and Considerations

  • Battery Drain. Using the CoreLocation API causes considerable battery drain on an iPhone. Because of this, it's important to use it as little as possible. There are several ways to reduce usage and therefore battery drain:

    • Only Check When Needed. By calling StartUpdatingLocation and StartUpdatingHeading only when you need the information, and calling StopUpdatingLocation and StopUpdatingHeading when you're finished with the data, the iPhone can actually turn off the underlying hardware that makes these calls. This can make the battery last significantly longer.
    • Set Your Accuracy. By default, the location data given by the iPhone will strive to be as accurate as possible. This may mean trying to poll more satellites, or resolving more Wi-Fi access points, etc. This also can cause significant battery drain. CLLocationManager has a property called DesiredAccuracy that can be set to your desired accuracy of location data. It expects a setting in meters, so setting it to 1000 will give it kilometer level accuracy. Setting to -1 will force it to be as accurate as possible.

  • Update Threshold. By default, location and heading data will be updated constantly. You can set a threshold level for how often you want the location and heading to be updated. CLLocationManager exposes the DistanceFilter and HeadingFilter properties, to set location and heading update threshold, respectively.

    • CLLocationManager.DistanceFilter. The value, in meters, of how far the device has to move laterally before a location update is sent. A value of -1 will cause it to update continuously.
    • CLLocationManager.HeadingFilter. The value, in degrees, of how far the device has to rotate before a heading update is sent. A value of -1 will cause it to update continuously.

  • Capabilities. The iPhone user can turn off location services altogether from the settings panel on the iPhone. Some users do this for privacy or battery life reasons. Additionally, the compass was introduced in the iPhone 3Gs model. The CLLocationManager exposes two properties, LocationServicesEnabled, and HeadingAvailable to give you information regarding them:

    • CLLocationManager.LocationServicesEnabled. If false, the user has this turned off, and if your application attempts to access location information via StartUpdatingLocation, the user will be given a prompt to allow the application to use location services.
    • CLLocationManager.HeadingAvailable. This is false on the versions of the iPhone that do not have a compass built in. If it's false, then you won't be able to get any meaningful heading data.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.