...仅供参考,必须正确格式化 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;
...此外,如果 v3 API 不正常,您可以使用相同的代码对 Google Map iframe 进行硬编码并将其嵌入到您的页面中...请参阅此处的简单教程:http: //pmcds.ca/blog/嵌入-google-maps-into-the-webpage.html
嵌入 并非完全正确的方法,但有时它会成为需要的解决方案。