Search code examples
perlgeoipgeoip2geolite2geolitecity

Does GeoLite2 provide coordinates?


I'm confused, does the free GeoLite2 database provide coordinates (latitude, longitude) anymore?

I have been using GeoLite and was able to use Geo::IP and ->latitude calls to get coordinates. I've looked through the documentation and grepped GeoIP2::Database::Reader but there are no references to coordinates. Seems like it is only available when querying Maxmind through the web API.

Note: After careful consideration, taking into account customer feedback, we have decided against removing latitude and longitude coordinates from the GeoLite2 databases.

Maxmind seems to suggest it should still be there? But how is it accessible with Perl then?


Solution

  • GeoLite2 provides latitude and longitude. With the Perl GeoIP2 API, you should be able to access as follows:

    my $reader = GeoIP2::Database::Reader->new(
        file    => '/path/to/database',
    );
    my $city = $reader->city( ip => '24.24.24.24' );
    say $city->location->latitude;
    say $city->location->longitude;
    

    Please note these coordinates are coarse estimates. See $city->location->accuracy_radius for the estimated accuracy (67% confidence level) of the coordinates in kilometers.