0Pricing
Swift Academy · Lesson

Geocoding and Regions

Convert coordinates to addresses and monitor regions.

What Is Geocoding?

Geocoding converts a human address into coordinates; reverse geocoding turns coordinates back into a readable address. Core Location provides CLGeocoder for both, talking to Apple's servers.

import CoreLocation
let geocoder = CLGeocoder()

Forward Geocoding an Address

Call geocodeAddressString(_:) with a free-form address. The completion returns an array of CLPlacemark objects; take the first and read its location.

geocoder.geocodeAddressString("Eiffel Tower, Paris") { placemarks, error in
    if let coord = placemarks?.first?.location?.coordinate {
        print(coord.latitude, coord.longitude)
    }
}

All lessons in this course

  1. Requesting Location Authorization
  2. Getting the User's Location
  3. Displaying Maps in SwiftUI
  4. Geocoding and Regions
← Back to Swift Academy