I have next PHP code
$str = $city . ', ' . $country . ', ' . $addr;
$address = urlencode($str);
$country = urlencode($country);
$json = file_get_contents("https://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$country");
$json = json_decode($json);
$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
if ($long and $lat) {
$sql = "`lat`='$lat',`lng`='$long',`edit_date`=NOW()";
$up_sql = "UPDATE `user_cards` SET " . $sql . " WHERE `id`='$id'";
}
This code works successfully in 90% of cases, the problem only occurs with certain addresses.
For example if $str="Bulgaria,Ravda,Emerald Beach Resort" and $country="Bulgaria", file_get_contents return NULL, but if i paste this string to maps.google.com, google succesfull find this address. Where is the mistake?