简体   繁体   中英

Google Places API

I'm writing a php script to find places using google places api Now I'm finding stuff and getting the results, other than public transport options. the 'bus_station, subway_station' etc options in types don't bring any results.

Anyone know the solution?

<?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>';
}
?>

Cheers David

Unfortunately it seems that the places API doesn't return too many results. Maybe you can try to use the local search API (http://code.google.com/apis/maps/documentation/localsearch/jsondevguide.html) for now, until the places API will improve. This is an example link 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

I just checked and there are no bus stations near to your LatLong, but if I increase the radius like so:

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

I get about ten results back:

{
   "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"
      },
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM