问问题
13260 次
3 回答
7
试试这个(结果为 json 格式):
public function getGeoPosition($address){
$url = "http://maps.google.com/maps/api/geocode/json?sensor=false" .
"&address=" . urlencode($address);
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
if($data['status']=="OK"){
return $data['results'];
}
}
print_r(getGeoPosition('chicago,il'));
于 2013-04-05T16:51:43.887 回答
0
If you have a Business account ,as suggested by your link, Google supply help. If you don't have a business account you would will need to use use This API which provides xml results. ie
http://maps.googleapis.com/maps/api/geocode/xml?address=anywhere&sensor=true
or
sensor=false
于 2013-04-05T16:23:43.167 回答
0
添加到穆罕默德的答案:
function getGeoPosition($address){
$url = "https://maps.google.com/maps/api/geocode/json?sensor=false" .
"&key=YOUR_API_KEY_HERE&address=" . urlencode($address);
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
if($data['status']=="OK"){
return $data['results'];
}
}
print_r(getGeoPosition('chicago,il'));
请注意,请求需要通过 https 进行,并且需要一个不受限制的 API 密钥。
于 2020-03-31T12:40:44.620 回答