Pear GeoNames help

I am trying to use the Pear Services GeoNames module, and need someone familiar with it to give me guidance on how to set up some inquiries.

I need:
All states and provinces in North America.
...
All cities in a particular State or Province.

All cities within X miles of a postal or zip code.

The documentation is very sparce, so if your are familiar with the GeoNames Pear module, I'll really appreciate your help.

LVL 6
birwinAsked:
Who is Participating?
 
Ray PaseurCommented:
Not sure if the PEAR part of this is a value-added feature or not.  I agree that the PEAR documentation is pretty sparse, but fortunately there is better documentation on the geonames project sites.  You need your own API key, then you can call the web services directly.

This is kind of a starting point to locate things about the GeoNames project:
http://www.geonames.org/
http://www.geonames.org/export/web-services.html

Some of the data:
http://download.geonames.org/export/dump/
http://download.geonames.org/export/zip/

The forum:
http://forum.geonames.org/gforum/forums/show/6.page

North America is abbreviated NA and has geonameId=6255149

All cities within X miles of a ZIP code presents an interesting question and one you may want to think carefully about.  ZIP or Postal Codes are not geographic locations; they are postal carriers' routes.  As such, a ZIP code might be only a building or two in Manhattan but might be hundreds of square miles in the large states out west.  In most American cities there are several ZIP codes and even though these are given geocodes (Latitude/Longitude pairs) in a variety of data bases, my experience has been that these data bases may not apply the rules about geocoding consistently.  Example: Should the geocode of a ZIP code be the approximate geological center of the polyline that outlines the carriers' routes?  Or should it be the rooftop of the post office that carries that ZIP code?  ZIP+4 codes have more accurate geocodes in some data bases, but the size of the data base is greatly increased.  Many of the free ZIP code location tables have huge amounts of inaccuracy (in one study I found 20% of the reported ZIP geolocations varied by multiple miles between data sets).  Hopefully the GeoNames project will help the community clean that information up.

That said, you can ask clients for their ZIP codes and if you know the geocodes of your stores, you can show them the stores that are closest to them.  This works right most of the time especially if you list the 5 closest stores.

Most distance calculations for short distances (guessing here: anything less than 150 miles) can be done with plane geometry.  Longer distance calculations use the Haversine formula.  Driving distances can be confounding because typical point-to-point distance algorithms do not take into account things like rivers and bridges.  So you generally will find that the distance you compute is the minimum distance and the actual driving distance is longer.  In my experience the driving distance worked out to about 1.25x the point-to-point distance once the distance got to be more than about 10 miles.  Driving distance more closely correlates to point-to-point distance as distances get longer.

This article may be helpful:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_4276-What-is-near-me-Proximity-calculations-using-PHP-and-MySQL.html

Best of luck with the project, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.