SwiftUI Maps & Location: Fundamentals

Mar 15 2022 · Swift 5.5, iOS 15, Xcode 13

Part 2: Core Location

18. Challenge: Find a Location

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 17. Geocode an Address Next episode: 19. Enable Region Monitoring

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 18. Challenge: Find a Location

The student materials have been reviewed and are updated as of January, 2022.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In the last episode you learned how to do a reverse geocode lookup. That is, you had a CLLocation and you converted into an address. In most cases, like this challenge, you’ll be doing the opposite. That is, you’ll have an address and you’ll want to convert it to a CLLocation. That’s the object of this challenge.

Challenge

In the challenge files, download the playground from this project. Your challenge is to convert the address to CLLocation. You’ll need to create a CLGeocoder object and then call geocodeAddressString. Print the location to the console. Pause the video and give it a shot.

Solution

How’d that challenge go for you. I’ll walk you through the process. Open up the challenge playground for this challenge. You’ll see it already has an address in place. We need to create a geocoder object.

let geocoder = CLGeocoder()
geocoder.geocodeAddressString(location) { placemarks, error in

}
  if let error = error {
    fatalError(error.localizedDescription)
  }
  guard let placemark = placemarks?.first else {
    return
  }
  print(placemark.location)