Reputation: 65
I am developing a PHP application to calculate the distance between 2 locations.
This is the code:
$GOOGLE_API_KEY = <MYAPIKEY>
$wayFrom = urlencode($wayFrom);
$wayTo = urldecode($wayTo);
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=".$wayFrom."&destinations=".$wayTo."&key=".$GOOGLE_API_KEY;
$out = @file_get_contents($url);
$data = json_decode($out);
$km = (int)($data->rows[0]->elements[0]->distance->value / 1000);
but from the file_get_contents statement I get an empty string.
The thing that bothers me the most is that, by inserting the string of the $url variable in the address of a browser, the call to the API works and I get the expected json code.
What could it be?
Upvotes: 0
Views: 27