Since iOS 3.0 it has been very easy for iPhone App developers to provide users with detailed information about their current location by using the built-in MKReverseGeocoder class. The MKReverseGeocoder class acts as an Objective C wrapper around Googles geocoding services and handles all the network activities as well as decoding of the returned result.
This all sounds very nice, except that you are only allowed to use the MKReverseGeocoder class if you also display the result in conjunction with a Google map. This may be perfectly fine for most Apps needing reverse geocoding but will effectively prevent other types of Apps from using this service. MyAlmanac is one of those Apps that fall into the latter category.
GeoNames Geocoding Services
GeoNames provides a multitude of different geocoding related services most of which are accessible using XML and JSON. In MyAlmanac we’re making use of two of these services:
“findNearby” is a reverse geocoding service that will return the name of the nearest toponym or locality given a latitude and longitude. Much like the built-in MKReverseGeocoder does. It does not provide you with the street name and number, but there are other services available for that. Besides for Apps like MyAlmanac it’s not really important whether you’re at a certain street address when it comes to calculation of sunrise and sunset.
The other service MyAlmanac is currently making use of is the “search” service. Based on the provided search criteria it will return a number of matching locations along with various information such as time zone, country, county, etc.
[AdSense - blog banner]
ILGeoNames Wrapper Classes
We have implemented a Objective C wrapper class called ILGeoNamesLookup in order to easily deal with the handling of HTTP and JSON. ILGeoNamesLookup provides methods for both the “findNearby” and “search” services.
We have also implemented a search controller called ILGeoNamesSearchController that makes it extremely easy to provide search facilities in iPhone Apps.
Both of these classes are currently being used in MyAlmanac to provide the various geocoding services. We’re now making these classes available to the public as Open Source under the terms of the BSD license.
The files can be downloaded from GitHub including a sample app that shows how to use the classes. You are also more than welcome to provide contributions, fixes, suggestions, etc. on these classes.
In the next tutorial I will go into more details about how these classes work and how you may use them in your own iPhone Apps.