#------------------------------------------------------------------------------ # File: geoloc.config # # Description: Definition for a Composite "GeoLocation" tag to geocode latitude # and longitude as city, state, country using a free online service. # # Notes: Requires "curl" (https://curl.se) and "jq" (https://jqlang.github.io/jq/) # to be installed. # # The -userparam language is optional and defaults to english (en). # # Tested with ExifTool 12.77 on macOS 12.6.3. # # # Examples: # > exiftool -config geoloc.config -gpslatitude -gpslongitude -geolocation image.jpg # # GPS Latitude : +38.861903 # GPS Longitude : -77.116753 # Geo Location : Arlington, Washington, US-VA, US # # Revisions: 2024/03/02 - Christian W. Correa Created #------------------------------------------------------------------------------ %Image::ExifTool::UserDefined = ( 'Image::ExifTool::Composite' => { GeoLocation => { Require => { 0 => 'Composite:GPSLatitude', 1 => 'Composite:GPSLongitude', }, ValueConv => q { return undef unless $$self{REQ_TAG_LOOKUP}{geolocation}; my $language = $self->Options(UserParam => 'Language'); $language or ($language = 'en'); # default language: english my $location = `curl --request GET --silent --url 'https://api.bigdatacloud.net/data/reverse-geocode-client?latitude=${val[0]}&longitude=${val[1]}&localityLanguage=${language}' | jq -M '. | .locality + ", " + .city + ", " + .principalSubdivisionCode + ", " + .countryCode'`; $location =~ s/\n|"//g; if ($location eq 'null' or $location eq '') { warn "Error while processing request."; return undef; } return $location; }, }, }, ); %Image::ExifTool::UserDefined::Options = ( CoordFormat => '%+.6f',# change default GPS coordinate format ); 1; #end