Hi,
I created 2 fields (latitude and longitude) to update a third field with “location name”, using Nominatim, with php code.
<?php
$lat_start = 47.5;
$lon_start = 4.5;
function getAddress($RG_Lat,$RG_Lon)
{
$json = “https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=”.$RG_Lat.”&lon=”.$RG_Lon.”&zoom=10&addressdetails=1″;
$ch = curl_init($json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0”);
$jsonfile = curl_exec($ch);
curl_close($ch);
$RG_array = json_decode($jsonfile,true);
return $RG_array[‘display_name’];
//$RG_array[‘address’][‘city’];
//$RG_array[‘address’][‘country’];
}
$addr = getAddress($lat_start,$lon_start);
echo “Address: “.$addr;
?>
Problem :
If I execute code with numbers ($lat = 47.5 and $lon = 4.5), it works fine.
But it doesn’t seem to work with variables. 🙁
How can I replace numbers with acf fields content (called “lat_start” and “lon_start”) ?