Hi,

I use location/gmap for my nodes.
I use nodes which have lat/lon but sometimes the region or city is not correctly inserted.
Could integration of geonames with location be used for reverse geocoding from lat/lon to city/region/country?

Thanks a lot in advance for your answer!
Greetings,
Martijn

Comments

bdragon’s picture

Integration would be nice.

(subscribing)

lyricnz’s picture

Status: Active » Postponed (maintainer needs more info)

You can always lookup country/subdivison using code like:

    // Lookup Tyrol, AT by lat/long
    $results = geonames_query('countrysubdivision', array('lat' => 47.03, 'lng' => 10.2));

and get results like

[15-Sep-2009 00:58:33] stdClass Object
(
    [standalone] => no
    [results] => Array
        (
            [0] => Array
                (
                    [countrycode] => AT
                    [countryname] => Austria
                    [admincode1] => 07
                    [adminname1] => Tyrol
                    [type] => ISO3166-2
                )

        )

    [total_results_count] => 1
    [service] => countrysubdivision
    [request] => Array
        (
            [url] => http://ws.geonames.org/countrySubdivision?lng=10.2&lat=47.03
            [bytes] => 334
            [seconds] => 0.745896100998
        )

    [query] => Array
        (
            [lng] => 10.2
            [lat] => 47.03
        )

)

How's that? Call the function above, and add information directly to your Location.

mgifford’s picture

Ok, I can confirm that geonames_query('countrysubdivision', array('lat' => 47.03, 'lng' => 10.2));

Works fine for me but if I have the place name , I was sure I could get other info with geonames_query('query', "Ottawa").

Looking at the API http://www.geonames.org/export/geonames-search.html I thought it would be worth trying geonames_query('q', "Ottawa") and a few other similar options to see if I could get an array from the API.


Any thoughts?

EDIT: Got it with

$query = array(
    'query' => "Ottawa",
    'maxrows' => 15,
    'featureclass' => array('P'),
    'featurecode' => array('PPL', 'PPLA', 'PPLG', 'PPLR', 'PPLC', 'PPLS', 'STLM'),
    'style' => 'full',
  );
print_r(geonames_query('search', $query));
lyricnz’s picture

The simpletest for geonames contains code that exercises all the search functions. That is a good place to look for working code

http://drupalcode.org/project/geonames.git/blob/HEAD:/tests/geonames.all...

http://drupalcode.org/project/geonames.git/blob/refs/heads/6.x-1.x:/test...

mgifford’s picture

Thanks @lyricnz - very useful to know that this has been done like this. Might be useful to add a pointer in the README.txt about this.

The 'featurecode' seems like an optional component. I really have no idea what that array does. Ahh, wait:
http://www.geonames.org/export/codes.html

Ok, so how would I do a search that's just in Canada?

lyricnz’s picture

The 'search' method supports passing a country to limit the result set - see http://www.geonames.org/export/geonames-search.html

You can probably just add country=CA to the query arguments:

http://api.geonames.org/search?q=london&maxRows=10&username=demo&style=f...

(untested, the demo account is out of quota for the day)

This is not the right place to be looking for support.

lyricnz’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

I don't think there's still an issue here?