谷歌地图API驾驶距离不准确

时间:2015-07-21 01:53:37

标签: php google-maps cakephp

我无法让Google API为驾驶距离提供与使用Google地图时相同的答案。我使用此数据来测试API与Google地图的准确性。我正在使用cakephp,但php代码也可以接受。

Test data for lat/long (not people I know) 
(point1)
Address Lat: -38.041968
Address Long: 145.26416599999993 

(point 2)
 Address Lat: -37.988981
Address Long: 145.53447499999993 

Google地图上这两个点之间的距离为41.3km,但在下面的谷歌api上相同的纬度/长点我得到33.7km,这是不可靠的依赖。谷歌API发生了什么,因为它似乎不起作用?

  $stlat = $student['Student']['address_lat'];
  $stlong = $student['Student']['address_long'];
  foreach ($tutors  as $key => $item):
     $tutlat = $item['Tutor']['address_lat']; //this is the lat/long above
     $tutlong = $item['Tutor']['address_long'];
     $testUrl = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=".$stlat.",".$stlong."&destinations=".$tutlat.",".$tutlong."&mode=driving&language=en&sensor=false";
     $data1 = file_get_contents($testUrl);
     $data = utf8_decode($data1);
     $obj = json_decode($data1);
     $dist2=$obj->rows[0]->elements[0]->distance->text;
     debug($obj->rows[0]->elements[0]->distance->text); //km
 endforeach;

1 个答案:

答案 0 :(得分:0)

答案是在谷歌地图上我没有得到最佳距离,但我在API上。所以问题解决了