[ACCEPTED]-Detect the nearest transit stop from the given location-gtfs

Accepted answer
Score: 28

Well, you could use the places-API to find 10 the nearest transit-stops, it works fine 9 for me for the given location.

Just do a 8 request with the parameters:

  • location (latlng-object of the given location)
  • radius(radius to search for in meters)
  • types(array of valid types, e.g. ['bus_station','subway_station'])

Checkout the fiddle: http://jsfiddle.net/doktormolle/aZrvs/

For retrieving 7 further details(bus service No, bus stop 6 ID) I don't have any good idea right now.

There 5 should be a way, those data on maps.google.com 4 will be retrieved by using AJAX, so there 3 is a ressource. But as long as there is 2 no public API to fetch those results it 1 would not be legal to use this ressource.

Score: 0

Adding &output=json to your initial 2 query (http://maps.google.com/maps?q=transit%20stop%20near%20New%20Bugis%20Street%20Singapore&output=json), is 1 not a legal way to get this information?

Score: 0

You can still enumerate all of Bus Service 7 Number, Bus Stop ID (Station Names) after 6 getting the google-places-api details, as 5 @Dr.Molle: said.

Open the webpage of detail['result']['url'], and 4 then XPath the string of bus ID list.

Below 3 is an example to get Taipei's bus Info around 2 a location (latitude, longitude). More detail 1 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)

More Related questions