Swift 101. Convert coordinates to city names and back

David Seek
Swift2Go
Published in
5 min readSep 5, 2018

--

Find more useful articles at www.davidseek.com

In this article I will explain how to get the names of the city, country, zip code, etc from a geo location object and the other way around.

The first thing we need to do is to set the needed permissions into the Info.plist file to be able to ask the User to access the GPS module of this phone. Open the Info.plist and set the following.

EnterNSLocationWhenInUseUsageDescription into the key field and press return. It will automatically turn into “Privacy — Location When…”. Same for NSLocationAlwaysUsageDescription .

Make sure to add a valid message, describing why the App needs the location permission, into the value field. A good text is important as Apple will reject the App when it just says “lorem impsum”. Been there. Literally done that 😁

You can chose whether you want to use “Location When In Use” or “Always”. Logically the first uses the GPS module only when the App is in opened. The latter uses the location even if the App is closed. Don’t use the second version unless you have a very good reason. Recently there has been US wide rioting in the streets when Uber changed the settings to “Always” for no obvious reason but tracking Users. Maybe not so literally 🤪

--

--