I need to get all the nearby public transit information within certain distance from a given location. The type of public transit can be either bus, train, et
Adding &output=json to your initial query (http://maps.google.com/maps?q=transit%20stop%20near%20New%20Bugis%20Street%20Singapore&output=json), is not a legal way to get this information?
You can still enumerate all of Bus Service Number, Bus Stop ID (Station Names) after getting the google-places-api details, as @Dr.Molle: said.
Open the webpage of detail['result']['url'], and then XPath the string of bus ID list.
Below is an example to get Taipei's bus Info around a location (latitude, longitude). More detail implementation see https://github.com/MikimotoH/gisTools/blob/master/google_place.py
places = get_web_json(
'https://maps.googleapis.com/maps/api/place/nearbysearch/json?' +
'key=%s&location=%f,%f' % (apikey, lat, lng) +
'&rankby=distance&language=zh-TW&types=bus_station')
if places['status'] == 'OK':
for result in places['results']:
placeid = result['place_id']
detail = get_web_json(
'https://maps.googleapis.com/maps/api/place/details/' +
'json?key=%s&placeid=%s' % (apikey, placeid) +
'&language=zh-TW')
station = detail['result']['name']
loc = detail['result']['geometry']['location']
buspage = get_webpage(detail['result']['url'])
tree = lxml.html.document_fromstring(buspage)
bus_elm = tree.xpath("/html/body/div[1]/div/div[4]/div[4]/div/div/div[2]/div/div[2]/div[1]/div[2]/div/div/div[2]/div/table/tr/td")[0]
buses = list(filter(lambda s: len(s.strip()) > 0,
bus_elm.text_content().strip().split()))
yield (station, float(loc['lat']), float(loc['lat']), buses)
Well, you could use the places-API to find the nearest transit-stops, it works fine for me for the given location.
Just do a request with the parameters:
latlng
-object of the given location)['bus_station','subway_station']
)Checkout the fiddle: http://jsfiddle.net/doktormolle/aZrvs/
For retrieving further details(bus service No, bus stop ID) I don't have any good idea right now.
There should be a way, those data on maps.google.com will be retrieved by using AJAX, so there is a ressource. But as long as there is no public API to fetch those results it would not be legal to use this ressource.