Google Places API

时间:2011-08-28 15:54:16

标签: php

我正在编写一个php脚本来使用google places api查找地点 现在我找到的东西和结果,除了公共交通选项。 “bus_station,subway_station”等类型的选项不会带来任何结果。

任何人都知道解决方案吗?

<?php

if(!$xml=simplexml_load_file('https://maps.googleapis.com/maps/api/place/search/xml?    location=51.500152,-0.126236&radius=50&types=bus_station&sensor=false&key=APIKEY')){
    trigger_error('Error reading XML file',E_USER_ERROR);
}
echo 'Displaying contents of XML file...<br />';
foreach($xml as $place){
    echo 'Name: '.$place->name.' <br>Locality: '.$place->vicinity.'<br>
Type: '.$place->type.' <br>lat: '.$place->geometry->location->lat.' long: '.$place->geometry->location->lng.'<br /><br>';
}
?>

干杯 大卫

2 个答案:

答案 0 :(得分:0)

不幸的是,places API似乎没有返回太多结果。也许您现在可以尝试使用本地搜索API(http://code.google.com/apis/maps/documentation/localsearch/jsondevguide.html),直到Places API得到改进。这是一个示例链接http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=bus%20station&sll=51.500152,-0.126236&rsz=8&sspn=0.01,0.01

答案 1 :(得分:0)

我刚检查过你的LatLong附近没有公交车站,但是如果我像这样增加半径:

https://maps.googleapis.com/maps/api/place/search/json
    ?location=51.500152,-0.126236&radius=500000&types=bus_station
    &sensor=true&key=[KEY]

我得到了十个结果:

{
   "html_attributions" : [],
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : 48.8004350,
               "lng" : 2.1278230
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "0b6c7686647f6b8484f0acff8584be1ee0147096",
         "name" : "Gare routière de Versailles",
         "reference" : "CoQBdAAAAH3-OwFohVy_S12pjM_ysTTnxQd6IeNfpQeAC3P5t2kRp8gD02xsC1IDS0tsETtJOJxoANexonNeVeU799oZvcZNwEMBbjcBE9wpS66H4q3JN3ErPr6RjYA23J0Fqq25JJfLO0X4qhvfxIbTglwhly0km8DFCJ3__YnW21IAhIC8EhCT7Hzf7k_lOMnF4yeXzDR7GhRDFVVlU-tg-VNl3LsLv60qK1JVsw",
         "types" : [ "bus_station", "establishment", "bus_station", "transit_station" ],
         "vicinity" : "Place Lyautey, Versailles"
      },
    ...