Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

acme (189)

  (email not shown publicly)

Leon Brocard (aka acme) is an orange-loving Perl eurohacker with many varied contributions to the Perl community, including the GraphViz module on the CPAN. YAPC::Europe was all his fault. He is still looking for a Perl Monger group he can start which begins with the letter 'D'.

Journal of acme (189)

Sunday September 29, 2002
07:46 AM


[ #8079 ]
To help me get location information for the Perl Monger groups I hacked up WWW::Gazetteer this morning, and it's on CPAN now...

    WWW::Gazetteer - Find location of world towns and cities

      use WWW::Gazetteer;
      my $g = WWW::Gazetteer->new();
      my $london = $g->fetch("London", "United Kingdom");
      print $london->{longitude}, ", ", $london->{latitude}, "\n";
      my $nice = $g->fetch("Nice", "France");
      my @bactons = $g->fetch("Bacton", "United Kingdom");
      # note: more than one Bacton in the UK!

    A gazetteer is a geographical dictionary (as at the back of an atlas).
    The `WWW::Gazetteer' module uses the information at to return geographical location (longitude,
    latitude) for towns and cities in countries in the world.

    Once you have imported the module and created a gazetteer object,
    calling fetch($town, $country) will return a list of hashrefs with
    longitude and latitude information.

      my $london = $g->fetch("London", "United Kingdom");
      print $london->{longitude}, ", ", $london->{latitude}, "\n";
      # prints -0.1167, 51.5000

    Note that there may be more than one town or city with that name in the
    country. In that case, you will get a list of hashrefs for each

    The following countries are valid: ...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I noticed a distinct lack of the US among the available cities list. (presumably because the isn't supplying the info?) Do you have a hybrid solution for also getting lat/longs for US cities?

  • Here's another database, that has lots of cities and aliases, with longitude, latitude and elevation: [].

    I've built a script that sucks the whole database (it was the subject of one of my lightning talks in Munich), but maybe it could be turned into a module, too. Is there room for this in the WWW::Gazetteer namespace?

    • Ah cool, I knew there was something like that. The Calle database also has elevation, it's just that I didn't find it useful ;-) Well, maybe we need a WWW::Gazetteer::Calle and a WWW::Gazetteer::HeavensAbove. What do you think?
      • Well, my script still needs to implement the optimisations I talked about in Munich... But if you provide a generic WWW::Gazetteer API, I can make WWW::Gazetteer::HeavensAbove follow it.

        If the module doesn't have to fetch the results of a request like "a*", and work around the 200+ answers limitation, that should be quick and easy (provided I find enough spare time to do it, obviously).

      • The Calle database also has elevation, it's just that I didn't find it useful ;-)

        Elevation is useful, if you want to produce a proper ICBM block [] for each perl monger group.

        I'm not sure who this would be useful for - it seems that we know Saddam Hussein's favourite brand of chocolate (Quality Street []) and computer manufacture (Sun []) - but do we have any idea what his favourite programming language is, and hence if we should be afraid?