46

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, etc..

Here is what I meant:

If I use Google Map to query "Transit Stop near a Location (e.g. Bugis Street Singapore)", then it will return us all the nearby Transit Stop that I want. Like the one shown in the picture. But I need its API to get those details out. (such as bus service No, bus stop ID, etc. as shown in the picture). But I couldn't found any.

Bus Stop

Here is what I've tried

  1. I have tried using the Google Map Nearby Place API to search for a place with the type of transit_station, bus_station, train_station,etc... But they all return Zero Result. I could only use this API to search for Nearby Place of Interest, but not nearby transit.

  2. I've also check Google Transit API, but I only found API to insert transit data to Google but Not to extract it out. I think Google didn't publicize the transit API yet.


Additional Information

I have check the site Gothere.sg. And confused How? because they able to detect the nearby transit. Is it only because they specify the direction "From-To".

I have read a pretty similar question on Detecting nearby transit. Perhaps It is not yet possible if we use Google APIs.

But nothing is impossible for me

Last Resort

As Last resort, I also check with the provider, publictransport.sg. I hack around with the API. And found out that it can provide me with a transit stop with some coordinate. But it lack a nearby API which found on Google Map.

So one workaround I could think of at the moment, is to use the provider in this case was publictransport.sg which give me the Stop ID and its coordinate. To do this, First, I have to translate the location name using the Google GeoCoding API into Coordinate then I have to create my own nearby calculation to find the nearby station by comparing the searched Coordinate against all the station coordinate that the provider have.

Now, it is possible for me, but very painful :-)


Back to the Question:

Is there a way to retrieve all transit stop data from a given location (either using Google Maps API or Any other API)? and How did u do that?


Thanks

At least thanks for reading my lengthy question. I appreciate any help from you.

starball
  • 20,030
  • 7
  • 43
  • 238
Yeo
  • 11,416
  • 6
  • 63
  • 90
  • I just stumbled across this page: [http://gothere.sg/api](http://gothere.sg/api) It might be worthwhile contacting them about there API and/or where they get there transit data from. – Chris Green Mar 06 '12 at 03:58
  • This page provides access to the gothere.sg API [http://gothere.sg/api/maps/overview.html](http://gothere.sg/api/maps/overview.html) – Chris Green Mar 06 '12 at 04:24
  • @Yeo, did you manage to get to the Stop ID eventually? – Rizon Apr 13 '14 at 10:07
  • @Rizon, I manage to get it with the publictransport.sg API. – Yeo Apr 14 '14 at 11:58

4 Answers4

28

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:

  • 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 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.

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
  • I've already tried about the place API. Thanks for making one for me on fiddle. Yes, U know what I want, Pull that detail out legally. Without hacking the Google Map API. Who know's there's a ways to... Thanks Dr.Molle :) – Yeo Feb 19 '12 at 18:05
  • It actually works, but it does not show all bus stops around within that given range. Any workaround? – richardaum Feb 01 '15 at 05:31
  • There is a limit of 20 for the number of returned results, that's how it is. – Dr.Molle Feb 01 '15 at 20:41
  • Note: the `types` parameter in Places API (Nearby and Text) Search is deprecated, but you can still use `type: "transit_station"` ─ See https://developers.google.com/places/web-service/search#PlaceSearchRequests – miguev Jun 16 '16 at 20:30
0

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?

Eduard
  • 3,536
  • 1
  • 20
  • 27
  • You probably meant to point to the (old, long gone) Geocoding API v2 (/maps/geo?q=...) but in any case a query of the form "transit stop near X" would not work reliably. It *might* have worked one day, but if a behavior is not documented as part of the API, it is not part of the API. – miguev Jun 16 '16 at 20:26
0

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)
MikimotoH
  • 393
  • 1
  • 4
  • 16
0

The Transitland APIs can answer your question. For example, try using the Transitland v2 REST API stops endpoint like this:

https://transit.land/api/v2/rest/stops?lat=xxx&lon=xxx&radius=1000&apikey=xxx

More information on the endpoint parameters and response at https://www.transit.land/documentation/rest-api/stops

Drew Dara-Abrams
  • 8,016
  • 11
  • 40
  • 48