![]() |
![]()
| ![]() |
![]()
NAMEImage::ExifTool::Geolocation - Determine geolocation from GPS and visa-versa SYNOPSISLook up geolocation information (city, region, subregion, country, etc) based on input GPS coordinates, or determine GPS coordinates based on city name, etc. DESCRIPTIONThis module contains the code to convert GPS coordinates to city, region, subregion, country, time zone, etc. It uses a database derived from geonames.org, modified to reduce the size as much as possible. METHODSReadDatabaseLoad Geolocation database from file. This method is called automatically when this module is loaded. By default, the database is loaded from "Geolocation.dat" in the same directory as this module, but a different directory may be used by setting $Image::ExifTool::Geolocation::geoDir before loading this module. Setting this to an empty string avoids loading any database. A warning is generated if the file can't be read. Image::ExifTool::Geolocation::ReadDatabase($filename);
ReadAltNamesLoad the alternate names database. Before calling this method the $altDir package variable may be set, otherwise AltNames.dat is loaded from the same directory as Geolocation.dat. This method is called automatically by "Geolocate" if the GeolocAltNames option is used and an input city name is provided. Image::ExifTool::Geolocation::ReadAltNames();
SortDatabaseSort database in specified order. Image::ExifTool::Geolocation::SortDatabase('City');
AddEntryAdd entry to Geolocation database. Image::ExifTool::Geolocation::AddEntry($city, $region, $subregion, $countryCode, $country, $timezone, $featureCode, $population, $lat, $lon, $altNames);
GetEntryGet entry from Geolocation database. my @vals = Image::ExifTool::Geolocation::GetEntry($num,$lang,$sort);
GetAltNamesGet alternate names for specified city. my $str = Image::ExifTool::Geolocation::GetAltNames($num,$sort);
GeolocateReturn geolocation information for specified GPS coordinates or city name. my @rtnInfo = Image::ExifTool::Geolocation::Geolocate($arg,$opts);
ALTERNATE DATABASESA different version of the cities database may be specified setting the package $geoDir variable before loading this module. This directory should contain the Geolocation.dat file, and optionally a GeoLang directory for the language translations. The $geoDir variable may be set to an empty string to disable loading of a database. When searching for a city by name, AltNames.dat is checked to provide additional possibilities for matches if the GeolocAltNames option is set and an AltNames.dat database exists. The package $altDir variable may be set to specify a different directory for AltNames.dat, otherwise the Geolocation.dat directory is assumed. The entries in AltNames.dat must match those in the currently loaded version of Geolocation.dat. ADDING USER-DEFINED DATABASE ENTRIESUser-defined entries may be created by defining them using the following technique before the Geolocation module is loaded. @Image::ExifTool::UserDefined::Geolocation = ( # city, region, subregion, country code, country, timezone, ['Sinemorets','burgas','Obshtina Tsarevo','BG','','Europe/Sofia', # feature code, population, lat, lon 'PPL',400,42.06115,27.97833], ); Similarly, user-defined language translations may be defined, and will override any existing translations. Translations for the default 'en' language may also be specified. See <https://exiftool.org/geolocation.html#Custom> for more information. USING A CUSTOM DATABASEThis example shows how to use a custom database. In this example, the input database file is a comma-separated text file with columns corresponding to the input arguments of the AddEntry method. $Image::ExifTool::Geolocation::geoDir = ''; require Image::ExifTool::Geolocation; open DFILE, "< $filename"; Image::ExifTool::Geolocation::AddEntry(split /,/) foreach <DFILE>; close DFILE; AUTHORCopyright 2003-2025, Phil Harvey (philharvey66 at gmail.com) This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The associated database files are based on data from geonames.org with a Creative Commons license. REFERENCES
SEE ALSOImage::ExifTool(3pm)
|