Geolocalising the app

As a test, we have used dummy coordinates, but we have a powerful GPS on board, and it's time to use it.

Using Core Location

To use the Core Location framework service, we need to instruct iOS that our app is using it.

To do this, we must add the NSLocationAlwaysUsageDescription key with a string; for example, this application requires location services to get the weather of your current location in Info.plist.

Then, we add a new property to PrettyWeatherViewController:

private var locationDatastore: LocationDatastore?

Next, we change the viewWillAppear function:

override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) locationDatastore = LocationDatastore() { [weak self] location in FlickrDatastore().retrieveImageAtLat(location.lat, ...

Get Swift: Developing iOS Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.