I have been struggling a lot to fix an issue related with Google distance matrix API call. Please the below code which I use to calculated distance between two calls. It work perfectly fine in localhost and one website hosted in Hostgator.
$details = 'https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=95864&destinations=91367&key=<API_KEY>' ;
$json = file_get_contents($details);
$details = json_decode($json, TRUE);
$distanceinmiles = ( $details['rows'][0]['elements'][0]['distance']['value'] * 0.000621371);
if($distanceinmiles > 0)
echo "Distance: " . $distanceinmiles ;
else
echo "Bad request";
is to be replaced with original API key.
The same code works in http://egressacademy.in/distance.php and shows the distance properly.
However, when the code is checked from another website from Enom hosting provider it failed.
I have also added Key restriction in Google API console for both server IP addresses.
Can anyone please advise how to fix this issues?