Kevin Kevin - 1 year ago 113
Swift Question

Forward Geocoding with Swift

I am looking to be able to have a user input an address, and be able to save that address, and convert it into latitude and longitudinal coordinates. I haven't been able to find much documentation on forward geocoding, and I am having trouble starting this code. Should I ask the user to input the address by (city, state, zip code)? Or would a single address suffice? Is there a function that can do what I need? Any help is much appreciated.

Answer Source

I have made a simple LocationManager helper on github in which you can get the thing what you want.

There is a function getReverseGeoCodedLocation in the library. Just input your address as a String and get the complete placemark and lat, longs.

Add the LocationManager.swift file in your project

How to use it:-

LocationManager.sharedInstance.getReverseGeoCodedLocation(address: yourAddress, completionHandler: { (location:CLLocation?, placemark:CLPlacemark?, error:NSError?) in

        if error != nil {

        if placemark == nil {
            print("Location can't be fetched")

        print(placemark?.addressDictionary?.description ?? "")


Internally it uses the geocodeAddressString of CLGeocoder


enter image description here Note:- It is for Swift 3.0 and above

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download