Tag Archives: iOS MapKit

Using Yandex Maps API & Core Location In iOS To Determine City Of a User By Reverse Geocoding

My goal was to determine the city or town name of a user to fill a region text field automatically in iOS app. At first I tried to use Core Location and MapKit, but I got only city names in English, for example, ‘Ufa’.  I had to get city names in Russian, so I decided to use Yandex Maps API. This is a final result – interface with a button to get city name automatically in Russian and a textField with a city name:

First, we add CLLocationManagerDelegate interface and an instance variable of CLLocationManager to get coordinates to our View Controller:

I created in my ViewController two helper methods to show and hide spinner without writing implementation of it:

I have a button on my ViewController. When it’s clicked a TextField is filled by a city name automatically after it is determined.

Here we tell, that our ViewController is a delegate of CLLocationManager.

This is a delegate method, that does all the remaining work. It is called after coordinates are determined. I used SBJson framework to parse JSON.

This is an error handling for Core Location:

This method shows an error if we failed to determine city automatically:

The same goal can be achieved using MapKit instead of Yandex Maps API for English city names:

Finally, some test locations. Replace the appropriate string to simulate another coordinates. This could be done in Simulator settings also in Debug/Geo section.