In my application, I am using the location module (non-CCK). I require nodes to have country, state / province and city. I harvest country and state via dropdown selects (and thus have the alphanumeric code provided by location module). City is then entered via a location-module text field.
I am very impressed with the geonames service and appreciate the work done here but I find the documentation a little thin - - and BTW, I would be happy to contribute code examples and other How-To's once I get my arms around this.
So - - Given country and state / province, I would like to do the following:
1) obtain a list of named cities for this country and state / province pair.
Having obtained this, I would then make certain the city is correctly entered.
2) once I have a valid a city, if the user enters zip / postal (this field is optional), I would then like to obtain a list of zip / postal codes for that city and make certain that the city - zip pair is valid.
3) alternatively, if the user enters zip / postal first, and then city, I would like to submit country and zip / postal and then check the city.
timely help would be greatly appreciated and I reiterate my offer to help - - and this includes creation of graphics if needed.
I have tried many variations using the geonames_query function with no luck.
thanks so much
S
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | Execute PHP Code | localhost.png | 204.63 KB | lyricnz |
Comments
Comment #1
lyricnz commentedThese are really questions for the Geonames service itself: this module only implements the XML web-services described at http://www.geonames.org/export/ws-overview.html.
Your queries may be better resolved by taking a complete dump of their data, and making SQL queries directly. Unfortunately, geonames doesn't seem to have APIs that directly correspond to your situation.
1) Do you really need to get a list of cities? Can't you just check it once they enter it, with a call to "search", restricted to the right (exact) name, Country+State/Province and restricted to type "PPL" (populated place).
eg: http://ws.geonames.org/search?name_equals=Miami&adminCode1=FL&country=US...
Or in PHP code:
You could even do a similar search to provide an auto-complete function.
2-3) Again, do you really need a list? Check a particular postal code using the "postalCodeSearch" service
eg: http://ws.geonames.org/postalCodeSearch?postalcode=33130&placename=Miami
Or in PHP code:
HTH, this response took quite a while to write.
Comment #2
newtonpage commented@ lyricnz
Thanks so much for your detailed reply. I had tried variations of the code you suggested before posting without favorable results.
You make excellent points concerning the approach and I am planning to make individual queries during a node addition from the geonames DB for the moment. I will then work on creating our own tables and refresh from the geoname dumps.
Regarding the geonames drupal module and the suggested code, here is what I have done as test:
First the city:
This does not work as shown below.
Examining the returned data (only the relevant section is shown):
However, doing the same without using the module (with somewhat more ponderous code):
This does work - - noting the camel-case in the returned object for totalResultsCount (versus underscore in the Drupal case).
Obviously, I would like to use the drupal module, but I cannot seem to make this query work.
I have similar results for zip - - this works:
Whereas this does not work (in any variation I tried):
So - - net-net: thank you so much for your help and consideration. I have to say that I do not understand why the drupal-based query (that is, the geonames module-based) query does not work, and I am sure it must be me since this (simple) application of the api must have been tested.
Again, suggestion welcome as I would prefer to do this within Drupal.
If you are interested, I will let you know as I continue to try to get this to work.
Thank again.
N
Comment #3
lyricnz commentedAre you using the latest (dev) version of geonames? I literally just ran the following PHP, and it worked fine (see screenshot).
Comment #4
lyricnz commentedPS: your code actually has a bug:
The third line should be checking $d_city_results->total_results_count not $d_city_valid->total_results_count
Comment #5
lyricnz commentedPPS: in your second example above, you can see the request URL is http://ws.geonames.net/search?username=ME&adminCode1=FL&name_equals=Miam...
If you open this in your browser, and view source, you can see the following XML:
It looks like you've configured a username as "ME" which should only be set if you have a paid-for commercial agreement with geonames.org. See the configuration in the "Geonames Commercial Webservices" section of the Geonames admin settings at /admin/settings/geonames
Comment #6
lyricnz commentedPPPS: I just fixed the support for returning error messages from geonames in #667744: Bad status messages from geonames not returned to user.
Also, I suggest you disable caching of geonames (in the geonames settings) while you're testing this kind of thing, or it might mess up your tests.
Comment #7
lyricnz commentedNo feedback for a month, closing.