Hello All,
I've liked the Piwigo-OpenStreetMaps plugin for a long time, but was very disapointed when I noticed in 2018 that the reverse geocoding in the Keywords tab no longer worked. I've finally taken the time to devise a fix by using the Mapquest Nominatim free service instead of the private Nominatim service that xbmgsharp, the author of the plugin, had been running.
I started modifying from version 2.9a of the extension.
One pre-requisite: you must sign up for and obtain your own API key for the service at https://developer.mapquest.com/.
the file in question is piwigo-openstreetmap/admin/admin_tag.php
Original code:
$osm_url = "https://nominatim-xbgmsharp.rhcloud.com/api/". $image['latitude'] ."/". $image['longitude'] ."/". $sync_options['language'];
Uncommented code & added my API key:
$osm_url = "https://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&addressdetails=1&zoom=12&lat=". $image['latitude'] ."&lon=". $image['longitude'] ."&key=".$my_API_key
You can either store your aPI key in a variable at the start of the script or replace ".$my_API_key with the actual value of your key.
Since the json returned by Mapquest is different from that expected by the original, this change:
Original code:
if (isset($response) and isset($response['success']) and isset($response['success'][0]) and isset($response['success'][0]['result']) and isset($response['success'][0]['result']['address']) and is_array($response['success'][0]['result']['address'])) { $response['address'] = $response['success'][0]['result']['address'];
replaced by:
if (isset($response) and is_array($response['address'])) {
In order to not violate the terms of Mapquest's service I added a one second delay just before the end of the images loop:
sleep(1); // wait 1 second after each photo } // Images loop
Because I slowed down the script so much that it gave a PHP execution timeout error when traversing a whole year's worth of photos, I added a local max time setting as the third executable statement at the top of the php file:
set_time_limit(900);
Lastly, thanks to erAck, I was able to properly escape any place names that Mapquest returns with what are normally be separators or PHP punctuation in them.
Original code:
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$tag_name) );
Modified:
$tag_escaped = pwg_db_real_escape_string($sync_options['osm_tag_group'].":".$tag_name); array_push( $tag_ids, tag_id_from_tag_name($tag_escaped) );
Regards,
JJF
Piwigo 2.10.2
Operating system: Linux
PHP: 7.0.33-0+deb9u8
MySQL: 5.5.5-10.1.44-MariaDB-0+deb9u1
Graphics Library: ImageMagick 6.9.7-4
Piwigo URL: http://fristersoft.net
Offline
Nice. Would you mind creating a pull request for https://github.com/xbgmsharp/piwigo-openstreetmap so the changes don't get lost? Thanks.
Offline
Hello erAck,
Good idea, but I won't commit to uploading my fix until i tweak a couple of things:
a) add the requested language variable to the Mapquest call -- Everything Itagged in the last 24 hours came back in native language, not the selected language. If anything, I'd like the tags to exist both ways.
b) add the API Key value as a configuration field in the plugin configuration tab.
Regards,
JJF
Offline