Geocoding

NOTE: The implementation has evolved since this blog post, please check the most recent Apple docs and Stack Overflow for additional info if you are still having trouble. Here's a good place to start.

Using Core Location to get a user’s current GPS Location is a cornerstone feature of thousands of great apps. It’s incredibly useful to calculate a user’s distance from a point of interest or determine if they are nearby to other users. With the GPS from a modern iPhone, you can even use reverse geocoding to quickly determine a user’s current street address.

If you try to implement Core Location in iOS 8 using previous tried and tested methods, you’ll start running into trouble the moment you attempt to add a <CLLocationManagerDelegate> to your code.

(1) After linking the Core Location framework in your Project Settings (near the bottom on the General tab), add this to the appropriate header file:

@import CoreLocation;

(2) In iOS 8, you must first call either:

// For use in background
requestAlwaysAuthorization (on the instance)
// For use in foreground
requestWhenInUseAuthorization (on the instance)

(3) Then, you must add a NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key to your project’s Info.plist containing the message to be displayed to the user at the prompt.

<key>NSLocationAlwaysUsageDescription</key>
<string>Your message goes here</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your message goes here</string>

The user will not be prompted unless one of these are added to the Info.plist.

Do you have thoughts or tips & tricks using Core Location with iOS 8?
Please leave a comment below!

 App Development, Apps

, , , , , , ,


Matthew's Blog
Home   Blog   LinkedIn   Contact Me
Connect on LinkedIn, Google+,

1 Comment

  1. saurav

    September 22, 2014

    Thanks a lot..It worked!!
    Apple din’t mention these stuffs in iOS 8 release notes, can you please specify where you got this?

Current focus: App & Web Development
Preferred Environments: OS X, iOS, Xcode, Sublime Text
Current skills: SWIFT, Objective-C, iOS SDK, CoreData, CoreAudio, JavaScript, HTML5, CSS, Wordpress
Degree: Bachelors of Science in Computer Information Systems Technology
from PURDUE University


© Website by Matthew Fecher
Denver, Colorado, USA.

top