How to Return Coordinates After Forward Geocoding

Forward Geocoding with Swift

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


Sample Image
Note:- It is for Swift 3.0 and above

Google Maps Reverse Geocoding only returning APPROXIMATE location

Figured this out pretty quickly. It was because I was including the bounds parameter in the request. Removing bounds gives me highly accurate results. I am now only using bounds in forward geocoding.

How to get world coordinate of a place by name or address

What you are looking for is called Forward Geocoding:

Forward geocoding converts location text into geographic coordinates, turning 2 Lincoln Memorial Circle NW into -77.050,38.889.

Get Coordinates for given Location

There is a built in API for that.

For iOS 5 and newer you can use CLGeocoder and for older version you will need to use some extern libraries.

Just call

- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler

where you want to get the location. It runs async and in the completionHandler you will get an array of all possible placemarks for your address where the first one is the most accurate. As apple says:

For most geocoding requests, this array should contain only one
entry. However, forward-geocoding requests may return multiple
placemark objects in situations where the specified address could not
be resolved to a single location.

Off topic:

Am I the only one whos first thoughts about Oxford was "What does he mean with this weird Hex value?"

Related Topics

Leave a reply