GMapsAddress (Retrieve addresses from Google Maps)

This add-in establishes the script column GMapsAddress that retrieves address information from Google Maps for images with GPS coordinates.

The address info Google sends back is quite detailed. For the moment I picked formatted_address but there is a lot more available. Have a look at the script for details and let me know what's interesting.

Support for video is in the making.

How to set up and use

:one: Get a Google API key

Sign up for Google Cloud services with your Google account and create an API key. That will give you access to several services, including maps. You'll have a free budget of 200 USD per month. 1.000 address retrievals cost 5 USD.

Check here for details:

https://cloud.google.com
https://developers.google.com/maps
https://mapsplatform.google.com/pricing

(I got mine years ago and don't remember all the individual steps. Feel free to comment and help others)

:two: Save ColumnGMapsAddress.js.txt to   ↓

%appdata%\GPSoftware\Directory Opus\Script AddIns

:three: Enter your API key in the script:

var apiKey = 'key looks like a really good password';

:four: Toggle the column with

Set COLUMNSTOGGLE="scp:GMapsAddress/GMapsAddress(!,a,0)"

Things you might enjoy reading

How to use buttons and scripts from this forum

The script's inner workings

JScript
function OnInit(initData) {
    initData.name = 'GMapsAddress';
    initData.version = '2023-11-28';
    initData.url = 'https://resource.dopus.com/t/gmapsaddress-retrieve-addresses-from-google-maps/47209';
    initData.desc = 'Retrieve addresses from Google Maps';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnAddColumns(addColData) {
    var col = addColData.AddColumn();
    col.name = 'GMapsAddress';
    col.method = 'OnColumn';
}

function OnColumn(scriptColData) {
    scriptColData.value = 'N/A';

    var item = scriptColData.item;
    if (item.is_dir) return;

    if (item.metadata != 'image') return;

    var lat = item.metadata.image.latitude;
    if (typeof (lat) != 'number') return;

    var lon = item.metadata.image.longitude;
    if (typeof (lon) != 'number') return;

    var apiKey = '';

    var url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + lat + ',' + lon + '&key=' + apiKey;

    var xhr = new ActiveXObject('MSXML2.XMLHTTP');
    xhr.open('GET', url, false);
    xhr.send();

    if (xhr.readyState == 4 && xhr.status == 200) {

        // Uncomment to see what Google sends back
        // DOpus.Output(item);
        // DOpus.Output(xhr.responseText);
        // DOpus.Output('------------------------------');

        var response = JSON.parse(xhr.responseText);

        if (response.results && response.results.length > 0) {
            scriptColData.value = response.results[0].formatted_address;
        } else {
            scriptColData.value = 'Address not found';
        }
    } else {
        scriptColData.value = 'No connection';
    }
}
1 Like

@lxp Have you seen this:

[GitHub - FrankBijnen/ExifToolGui: A GUI for ExifTool]

He uses other reverse mapping options. However, I haven't got it to work with video files yet.