...仅供参考,JSON请求URL必须正确格式化才能返回任何好的内容,否则您可能会得到NULL响应。
例如,这是我从 JSON 响应中检索经度和纬度值的方式:
// some address values
$client_address = '123 street';
$client_city = 'Some City';
$client_state = 'Some State';
$client_zip = 'postal code';
// building the JSON URL string for Google API call
$g_address = str_replace(' ', '+', trim($client_address)).",";
$g_city = '+'.str_replace(' ', '+', trim($client_city)).",";
$g_state = '+'.str_replace(' ', '+', trim($client_state));
$g_zip = isset($client_zip)? '+'.str_replace(' ', '', trim($client_zip)) : '';
$g_addr_str = $g_address.$g_city.$g_state.$g_zip;
$url = "http://maps.google.com/maps/api/geocode/json?
address=$g_addr_str&sensor=false";
// Parsing the JSON response from the Google Geocode API to get exact map coordinates:
// latitude , longitude (see the Google doc. for the complete data return here:
// https://developers.google.com/maps/documentation/geocoding/.)
$jsonData = file_get_contents($url);
$data = json_decode($jsonData);
$xlat = $data->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$xlong = $data->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
echo $xlat.",".$xlong;
...此外,您可以使用相同的代码对Google Map iframe进行硬编码,并在v3 API不表现时将其嵌入到您的页面中...在这里查看简单的教程:http://pmcds.ca/blog/embedding-google-maps-into-the-webpage.html
嵌入并不完全是正确的方法,但有时它成为需要的解决方案。