Reputation: 33
I am trying to use the Google Maps Elevation API but its not returning any results. The code I am using is below:
<?php
$results = file_get_contents("https://maps.googleapis.com/maps/api/elevation/json?locations=-37.8,144.815&key=[myAPIkey]&sensor=false");
//$results = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address=Paris,France&sensor=false&key=[myAPIkey]");
$json = json_decode($results, true);
echo ${results};
//print_r($json); ?>
The commented parts are using the Geocoding API which works for me but as soon as I change the $results variable to the Elevation API it does not return any results at all. When I put the URL in my browser I get results.I have enabled the API in the console and have a working API key.
Has anyone got any ideas why this isn't working?
Upvotes: 3
Views: 839
Reputation: 385
Make sure on your API console that Elevation API is enabled and your browser application key have Any referrer allowed
or if you use server application key Any IP allowed
Otherwise try using cURL
$curlUrlRequest = 'https://maps.googleapis.com/maps/api/elevation/json?locations=-37.8,144.815&key=[myApiKey]&sensor=false';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $curlUrlRequest);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
var_dump($response);
Upvotes: 3