16

Is there an (offline) Geocoding framework, library or database for iOS? A place to get the data from?

I need to be able to geocode street addresses in cities worldwide (or at least in the United States) into latitude and longitude for sunrise and sunset calculations.

The information must be in a format that will work on iPhone OS. (Either a database file or written in C/Objective-C)

Moshe
  • 57,511
  • 78
  • 272
  • 425

6 Answers6

31

What I would recommend :

  • Get the data from Open Street Maps, the license just implies that you mention the source. There are some OSM extracts for some countries, I don't know if there are some already made for some cities, but this can be achieved on your side I think.

[EDIT] As an example, you can download data from http://www.openstreetmap.org , just click on the export tab, choose the Open Street Map XML Data format, and then export data: you'll get the OSM data for the chosen bounding box. Some more data can be downloaded from cloudmade : http://downloads.cloudmade.com/

  • Then import this data into a sqlite DB . Then create a spatial index from this sqlite DB with geographic info in it : such thing can be achieved using spatialite ( spatialite is a very good GIS extension to Sqlite)

[EDIT] Spatialite provides a GUI tool to create a spatial database from various data source formats. The tool can be downloaded as binary from here : http://www.gaia-gis.it/spatialite-2.4.0-4/binaries.html (spatialite_gui) I'm linking to the 2.4.0 beta because that's the one that best supports .osm files.

Another good ressource is QGis to visualiaze OSM data / create spatialite DB. It's free / open source and very mature: http://www.qgis.org/

  • once you've done this, you'll be able to implement a basic geocoder because spatialite implements functions such as "give me the nearest line to this GPS coord" (basic GIS feature).

These are the very rough lines. I can go in much more deeper details if you're interested in such approach : I've achieved this on my side. I know how to compile spatialite for iOS (this took me some time....) and also how to import OSM data and create spatial indexes for it.

yonel
  • 7,855
  • 2
  • 44
  • 51
  • Please do explain more, I'd appreciate it. Specifically, how/where do I download the Open Street Maps data from? Also, please explain how to do the database import and the spacialite thing. Thank you! – Moshe Dec 11 '10 at 23:37
  • 1
    I've added some more details. If you find my answer interesting , please vote up ! ;) – yonel Dec 12 '10 at 20:42
  • added reference to QGis. I've just downloaded and tried the 1.6.0 version, support for OSM has been improved, same for spatialite. – yonel Dec 14 '10 at 12:29
  • Have you Spatialite built along with GEOS and Proj.4? I have now bare Spatialite built against iOS, but when I look at GEOS sources, it becomes scary. :) – Aleks N. Jan 12 '11 at 10:45
  • Also do I understand it right, that to build spatial index all I need is to create a table with Geometry column, and then call "Create Spatial Index" in spatial-gis app? I did that and got an index. I'm just not sure it's so easy... :) The app was very fast to do it, while I thought it's some "intellectual" and long task... – Aleks N. Jan 12 '11 at 10:51
  • Sorry, and one more question. You say Spatialite implements functions such as "give me the nearest line". I was looking here and there in documentation, but found only a function that gives out distance between two Geometry objects. Could you please name the function that can help me, i.e. give the Linestring nearest to a Point, in SQL or C API? – Aleks N. Jan 12 '11 at 10:53
  • 1
    For all that are interested, here is the answer to my last two comments: http://groups.google.com/group/spatialite-users/browse_thread/thread/34609c7a711ac92d/68f3bc5783b32065?lnk=gst&q=distance#68f3bc5783b32065 – Aleks N. Jan 12 '11 at 16:11
  • OK, also managed to find the reply to my first question. :) http://stackoverflow.com/questions/1782639/geospatial-library-for-the-iphone – Aleks N. Jan 12 '11 at 18:37
  • @Aleks: the SQL function to measure the distance between 2 geometries is distance() http://www.gaia-gis.it/spatialite/spatialite-sql-2.3.1.html#p13 This is mapped in the spatialite code to the c function "gaiaMinDistance". As far as I remember this is expressed in radians. The coming 2.4.0 adds a function to get the distance in meters ST_distance: http://www.gaia-gis.it/spatialite-2.4.0-4/spatialite-sql-2.4-4.html#p13 – yonel Jan 14 '11 at 09:20
  • More info on this thread http://stackoverflow.com/questions/4793970/how-to-compile-spatialite-for-ios/4863757#4863757 I've made a static lib .a for spatialite. (mark as answer ? ;) – yonel Feb 02 '11 at 09:18
1

I am not sure how to do the thing you want to do, but here is some frameworks:

http://code.google.com/apis/maps/documentation/geocoding/ (online) http://www.gisgraphy.com/ (i think it is offline)

this link may also help you:

How to convert an address to a latitude/longitude?

Hope this helped :)

EDIT:

This may also help you on the way :) http://www.geonames.org/export/

while searching for the answer i found out that some people claim that this is resource intensive, and i think they may be right :) so consider that when you are creating your application ;)

Community
  • 1
  • 1
0

In case developers are searching for a tutorial for the OpenStreetMaps path, I strongly recommend this tutorial:

http://shikii.net/blog/offline-maps-in-ios-using-openstreetmap-and-route-me/

It's a simple tutorial to get you started with the Open Street Maps, which uses the Route-me github repository. Here is an example application on github:

https://github.com/Label305/iOS-OfflineMaps-Example

Hope this helps

Paolo Bernasconi
  • 2,010
  • 11
  • 35
  • 54
0

I don't think there is an existing framework available. However you could do worse than contacting the author of this dupe: Reverse Geocoding Without Web Access

Community
  • 1
  • 1
Rog
  • 17,070
  • 9
  • 50
  • 73
0

This answer could be of help: How to convert an address to a latitude/longitude?

You might have to do some extra work.

Community
  • 1
  • 1
samxli
  • 1,536
  • 5
  • 17
  • 28
0

All addresses of every single place in the world (or the US)... That takes a lot of space, more than the average iOS device can handle. So, definitely not an offline version.

However, you can simply use Open Street Maps which can help you get some data, store this in some kind of cache (store only everything in a 5 miles radius, for example) and refresh this cache when you leave the area.

Tom van der Woerdt
  • 29,532
  • 7
  • 72
  • 105