如何使用PHP从地址谷歌地图获取经度和纬度

时间:2016-05-24 11:53:34

标签: php google-maps

我有一个地址并使用我想要获取其精确的纬度和经度,

但是当我运行我的代码时,它给了我一些其他位置的纬度和经度。

我想要的输出

enter image description here

输出我

enter image description here

请帮帮我

提前致谢

switch(test){
  case 1: {
    let bla = getBlaForTest(test);
  }
}

3 个答案:

答案 0 :(得分:1)

使用类似的东西:

<?php
$address = "Cafe Coffee Day, INSIDE HPCL Petrol Bunk, Mumbai - Goa Highway,    Mangaon, Maharashtra, India";
 $url = "http://maps.google.com/maps/api/geocode/json?address=".urlencode($address)."&sensor=false&region=India";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
echo $lat = $response_a->results[0]->geometry->location->lat;
echo "<br />";
echo $long = $response_a->results[0]->geometry->location->lng;

?>

输出为enter image description here

答案 1 :(得分:0)

$lat = $output->results[0]->geometry->bounds->northeast->lat;
$long = $output->results[0]->geometry->bounds->northeast->lng;

更改为:

$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;

答案 2 :(得分:0)

将echo语句更改为

030 230 - - - - - - -
230 330 - - NA NA - - -
430 530 R F G H K - -
530 630 R F NA NA G H K
630 730 R F G H K - -

注意:从变量中删除尾随i