.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Image::ExifTool::Geolocation 3" .TH Image::ExifTool::Geolocation 3 2024-11-01 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Image::ExifTool::Geolocation \- Determine geolocation from GPS and visa\-versa .SH SYNOPSIS .IX Header "SYNOPSIS" Look up geolocation information (city, region, subregion, country, etc) based on input GPS coordinates, or determine GPS coordinates based on city name, etc. .SH DESCRIPTION .IX Header "DESCRIPTION" This 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. .SH METHODS .IX Header "METHODS" .SS ReadDatabase .IX Subsection "ReadDatabase" Load 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 \f(CW$Image::ExifTool::Geolocation::geoDir\fR 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. .PP .Vb 1 \& Image::ExifTool::Geolocation::ReadDatabase($filename); .Ve .IP Inputs: 4 .IX Item "Inputs:" 0) Database file name .IP "Return Value:" 4 .IX Item "Return Value:" True on success. .SS ReadAltNames .IX Subsection "ReadAltNames" Load the alternate names database. Before calling this method the \f(CW$altDir\fR 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. .PP .Vb 1 \& Image::ExifTool::Geolocation::ReadAltNames(); .Ve .IP Inputs: 4 .IX Item "Inputs:" (none) .IP "Return Value:" 4 .IX Item "Return Value:" True on success. May be called repeatedly, but AltNames.dat is loaded only on the first call. .SS SortDatabase .IX Subsection "SortDatabase" Sort database in specified order. .PP .Vb 1 \& Image::ExifTool::Geolocation::ReadDatabase(\*(AqCity\*(Aq); .Ve .IP Inputs: 4 .IX Item "Inputs:" 0) Sort order: 'Latitude', 'City' or 'Country' .IP "Return Value:" 4 .IX Item "Return Value:" 1 on success, 0 on failure (bad sort order specified). .SS AddEntry .IX Subsection "AddEntry" Add entry to Geolocation database. .PP .Vb 3 \& Image::ExifTool::Geolocation::AddEntry($city, $region, \& $subregion, $countryCode, $country, $timezone, \& $featureCode, $population, $lat, $lon, $altNames); .Ve .IP Inputs: 4 .IX Item "Inputs:" 0) City name (UTF8) .Sp 1) Region, state or province name (UTF8), or empty string if unknown .Sp 2) Subregion name (UTF8), or empty string if unknown .Sp 3) 2\-character ISO 3166 country code .Sp 4) Country name (UTF8), or empty string to use existing definition. If the country name is provided for a country code that already exists in the database, then the database entry is updated with the new country name. .Sp 5) Time zone identifier (eg. "America/New_York") .Sp 6) Feature code (eg. "PPL"), or empty if not known .Sp 7) City population .Sp 8) GPS latitude (signed floating point degrees) .Sp 9) GPS longitude .Sp 10) Optional comma-separated list of alternate names for the city .IP "Return Value:" 4 .IX Item "Return Value:" 1 on success, otherwise sends a warning message to stderr .SS GetEntry .IX Subsection "GetEntry" Get entry from Geolocation database. .PP .Vb 1 \& my @vals = Image::ExifTool::Geolocation::GetEntry($num,$lang,$sort); .Ve .IP Inputs: 4 .IX Item "Inputs:" 0) Entry number in database, or index into sorted database .Sp 1) Optional language code .Sp 2) Optional flag to treat first argument as an index into the sorted database .Sp item Return Values: .Sp 0) City name, or undef if the entry didn't exist .Sp 1) Region name, or "" if no region .Sp 2) Subregion name, or "" if no subregion .Sp 3) Country code .Sp 4) Country name .Sp 5) Time zone .Sp 6) Feature code .Sp 7) City population .Sp 8) GPS latitude .Sp 9) GPS longitude .Sp 10) Feature type, or undef .SS GetAltNames .IX Subsection "GetAltNames" Get alternate names for specified city. .PP .Vb 1 \& my $str = Image::ExifTool::Geolocation::GetAltNames($num,$sort); .Ve .IP Inputs: 4 .IX Item "Inputs:" 0) Entry number in database or index into the sorted database .Sp 1) Optional flag to treat first argument as an index into the sorted database .IP "Return value:" 4 .IX Item "Return value:" Comma-separated string of alternate names for this city. .IP Notes: 4 .IX Item "Notes:" "ReadAltNames" must be called before calling this routine. .SS Geolocate .IX Subsection "Geolocate" Return geolocation information for specified GPS coordinates or city name. .PP .Vb 1 \& my @rtnInfo = Image::ExifTool::Geolocation::Geolocate($arg,$opts); .Ve .IP Inputs: 4 .IX Item "Inputs:" 0) Input argument ("lat,lon", "city", "city,country", "city,region,country", etc). When specifying a city, the city name must come first, followed by zero or more of the following in any order, separated by commas: region name, subregion name, country code, and/or country name. Regular expressions in \f(CW\*(C`/expr/\*(C'\fR format are also allowed, optionally prefixed by "ci", "re", "sr", "cc" or "co" to specifically match City, Region, Subregion, CountryCode or Country name. Two special controls may be added to the argument list: .Sp .Vb 3 \& \*(Aqboth\*(Aq \- When search input includes both name and GPS coordinates, use \& both to determine the closest city matching the specified \& name(s) instead of using GPS only. \& \& \*(Aqnum=##\*(Aq \- When the search includes GPS coordinates, return the nearest \& ## cities instead of just the closest one. Returned cities \& are in the order from nearest to farthest. .Ve .Sp See for more details. .Sp 1) Optional reference to hash of options: .Sp .Vb 2 \& GeolocMinPop \- Minimum population of cities to consider in search. \& Default 0. \& \& GeolocMaxDist \- Maximum distance (km) to search for cities when an \& input GPS position is used. Default infinity. \& \& GeolocMulti \- Flag to return multiple cities if there is more than \& one match. Used in the case where no input GPS \& coordinates are provided. Default 0. \& \& GeolocFeature \- Comma\-separated list of feature codes to include in \& search, or exclude if the list starts with a dash (\-). \& Default undef. \& \& GeolocAltNames \- Flag to search alternate names database if available \& for matching city name (see ALTERNATE DATABASES below). \& Default undef. .Ve .IP "Return Values:" 4 .IX Item "Return Values:" 0) Reference to list of database entry numbers for matching cities, or undef if no matches were found. .Sp 1) Reference to list of distance/bearing pairs for each matching city, or undef if the search didn't provide GPS coordinates. .SH "ALTERNATE DATABASES" .IX Header "ALTERNATE DATABASES" A different version of the cities database may be specified setting the package \f(CW$geoDir\fR variable before loading this module. This directory should contain the Geolocation.dat file, and optionally a GeoLang directory for the language translations. The \f(CW$geoDir\fR variable may be set to an empty string to disable loading of a database. .PP 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 \f(CW$altDir\fR 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. .SH "ADDING USER-DEFINED DATABASE ENTRIES" .IX Header "ADDING USER-DEFINED DATABASE ENTRIES" User-defined entries may be created by defining them using the following technique before the Geolocation module is loaded. .PP .Vb 6 \& @Image::ExifTool::UserDefined::Geolocation = ( \& # city, region, subregion, country code, country, timezone, \& [\*(AqSinemorets\*(Aq,\*(Aqburgas\*(Aq,\*(AqObshtina Tsarevo\*(Aq,\*(AqBG\*(Aq,\*(Aq\*(Aq,\*(AqEurope/Sofia\*(Aq, \& # feature code, population, lat, lon \& \*(AqPPL\*(Aq,400,42.06115,27.97833], \& ); .Ve .PP 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 for more information. .SH "USING A CUSTOM DATABASE" .IX Header "USING A CUSTOM DATABASE" This 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. .PP .Vb 5 \& $Image::ExifTool::Geolocation::geoDir = \*(Aq\*(Aq; \& require Image::ExifTool::Geolocation; \& open DFILE, "< $filename"; \& Image::ExifTool::Geolocation::AddEntry(split /,/) foreach ; \& close DFILE; .Ve .SH AUTHOR .IX Header "AUTHOR" Copyright 2003\-2024, Phil Harvey (philharvey66 at gmail.com) .PP 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. .SH REFERENCES .IX Header "REFERENCES" .IP 4 .IX Item "" .PD 0 .IP 4 .IX Item "" .PD .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBImage::ExifTool\fR\|(3pm)