Geo::Coder::OSM(3pm)
π Geo::Coder::OSM π
bestie. you want to turn a human address into actual coordinates?? and you want the OpenStreetMap besties to do it for you?? say less, this is literally the module for that. it's called Geo::Coder::OSM and it lives in the perl family of manual pages (3pm girlies rise) π
πΈ NAME πΈ
Geo::Coder::OSM β geocode addresses with the OpenStreetMap Nominatim API πΊοΈβ¨
π SYNOPSIS π
use Geo::Coder::OSM;
my $geocoder = Geo::Coder::OSM->new;
my $location = $geocoder->geocode(
location => 'Hollywood and Highland, Los Angeles, CA'
);
no cap, that's it. four lines and you're geocoding. iconic behavior honestly π
π¦ DESCRIPTION π¦
The Geo::Coder::OSM module is an interface β a whole little doorway β into the OpenStreet Nominatim geocoding service. that's the vibe. that's the whole vibe. β¨
π METHODS π
π new π
$geocoder = Geo::Coder::OSM->new()
$geocoder = Geo::Coder::OSM->new(
ua => $ua,
sources => [ 'osm', 'mapquest' ],
debug => 1,
)
creates a brand new geocoding object, main character energy, fresh out the box π
- you can pass in a
uaparameter if you want to hand it your own customLWP::UserAgentobject π€ - you can pass in a
sourcesparameter to pick your data sources. the currently valid values areosmandmapquest, and the default isosm. - wanna cycle between different sources? pass an array reference as the value for
sourcesand it'll rotate through them π - wanna make your own sources? go look at SOURCES below, it's right there π«Ά
π geocode π
$location = $geocoder->geocode(location => $location)
@locations = $geocoder->geocode(location => $location)
context matters here bestie, and it's giving β¨polymorphismβ¨:
- in scalar context, this method gives you back the first location result π₯
- in list context, it gives you back all the location results π
every single location result is a hashref. a typical one is giving:
{
address => {
city => "Los Angeles",
country => "United States of America",
country_code => "us",
hamlet => "Hollywood",
road => "Hollywood Boulevard",
station => "Hollywood/Highland",
suburb => "Little Armenia",
},
boundingbox => [
"34.101634979248", "34.1018371582031",
"-118.339317321777", "-118.33910369873",
],
class => "railway",
display_name =>
"Hollywood/Highland, Hollywood Boulevard, Little Armenia, Hollywood, Los Angeles, United States of America",
icon =>
"http://nominatim.openstreetmap.org/images/mapicons/transport_train_station2.p.20.png",
lat => "34.101736",
licence =>
"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.",
lon => "-118.33921",
osm_id => 472413621,
osm_type => "node",
place_id => 9071654,
type => "station",
}
look at all those fields. boundingbox? osm_type? licence? we are FED ππ
π reverse_geocode π
$location = $geocoder->reverse_geocode(lat => $lat, lon => $lon)
$location = $geocoder->reverse_geocode(latlng => "$lat,$lon")
the reverse uno card π β you hand it a lat/lon pair and it hands you back a location result. two ways to do it, pick your fighter:
- pass
latandlonseparately, or - pass
latlngas a"$lat,$lon"string π
π response π
$response = $geocoder->response()
gives you back an HTTP::Response object for the last request you sent. super useful when something goes wrong and you're like "what happened π" β this is how you find out the details of the error π
π ua π
$ua = $geocoder->ua()
$ua = $geocoder->ua($ua)
accessor for the UserAgent object. read it, or set it, whichever you need π«Ά
π SOURCES π
to define additional sources, you just add them to the %SOURCES package variable, like so:
$Geo::Coder::OSM::SOURCES{local} = 'http://127.0.0.1/api_base_path';
$Geo::Coder::OSM::SOURCES{internal} = 'http://internal.corp/api_base_path';
boom. now local and internal are sources. you're welcome π
π₯ SEE ALSO π₯
π REQUESTS AND BUGS π
found a bug? want a feature? pls pls pls report it here:
<http://rt.cpan.org/Public/Bug/Report.html?Queue=Geo-Coder-OSM>
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. so it's a whole two-way thing, mutual, a little relationship, we love to see it π«Άβ¨
π§ SUPPORT π§
you can find documentation for this module with the perldoc command:
perldoc Geo::Coder::OSM
you can also look for information at:
- GitHub Source Repository
<http://github.com/gray/geo-coder-osm>
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/Geo-Coder-OSM>
- CPAN Ratings
<http://cpanratings.perl.org/d/Geo-Coder-OSM>
- RT: CPAN's request tracker
<http://rt.cpan.org/Public/Dist/Display.html?Name=Geo-Coder-OSM>
- Search CPAN
<http://search.cpan.org/dist/Geo-Coder-OSM/>
π COPYRIGHT AND LICENSE π
Copyright (C) 2010-2013 gray <gray at cpan.org>, all rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
β AUTHOR β
gray, <gray at cpan.org>
and that's the whole page bestie π perl v5.36.0, dated 2022-10-15, and yes this is Geo::Coder::OSM(3pm) β go geocode something and slay β¨π
π¦ where this page comes from
- ubuntu noble: libgeo-coder-osm-perl 0.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libgeo-coder-osm-perl 0.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libgeo-coder-osm-perl 0.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms