8

Here is my situation, maybe someone could give a hint towards the solution or maybe point out that its not possible:

I have bus routes just defined by the streets that the buses pass, like this:

W 49th St,
10th Ave,
W 65th St,
79th Street Transverse Rd,
5th Ave,
...

I want to get this data and create a visual route in Google Maps. I had a little experience with Gmaps before, but only using the web-service to get directions between points.

In this case the web-service utilized that way is useless because if I ask directions considering every point (A, B, C) is a street, GMaps create a route that goes from "W 49th St" to the middle of "10th Ave" then to the middle of "W 65th St", etc.

I think I could accomplish this if there is a way to get the map data and create the route myself by navigating the map and looking for the shortest paths given a set of streets.

Can I have this kind of information from Google Maps or maybe someway easier to do this?

Thanks.

direndd
  • 642
  • 2
  • 16
  • 47
John W. Nesk
  • 175
  • 1
  • 3
  • 6

1 Answers1

13

The only real option for getting bus route information from the Google Maps API v3 is to use the directions service with the mode set to TRANSIT. Whether it returns data or not will depend on what city you are looking for that information in.

Example transit route

The "manual" option is to use the directions service to get directions [with mode DRIVING] between the actual stops on the route, your current list isn't detailed enough to do that, but if you have the coordinates of the stops, it can be done (or you can attempt to capture a route using draggable directions).

Example using multiple directions requests

geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • What if I could find the coordinates of the intersection between two streets? I could use them as waypoints. In the example I would ask GMaps directions for: "W 49th St" to "5th Ave" with waypoints: [intersection("W 49th St","10th Ave"), intersection("10th Ave","W 65th St"), ... ] – John W. Nesk Mar 09 '13 at 21:21
  • It is hard to say, might work. It would be really helpful if you could reveal what city you are attempting to do this in. – geocodezip Mar 09 '13 at 21:37
  • Do you know a way to find the intersection? The city I'm trying this is in Brazil, witch doesnt have the TRANSIT coverage. The only data about the public transportation is that I refered. – John W. Nesk Mar 09 '13 at 21:55
  • You could try viewing in streetview (if that covers Brazil) and alert (or tag) each of the coords as you move down the street, until you get to one that shows the other roads from the intersection. That would give you the lat,long – Rafe Mar 09 '13 at 22:03
  • Rafe, I need to do that only by code, there are 402 bus lines, it would take too much time – John W. Nesk Mar 09 '13 at 22:09
  • Is Brazil the city or the country? You said "The only data about the public transportation is that I refered", where did you mention that I can't find it in your question or your comments. – geocodezip Mar 09 '13 at 22:49
  • In Brazil the country. What I'm trying to say is that Google Maps doesnt have information about public transportation in the city I'm trying this. The only available information is a list of streets where the buses pass found in the website of the bus company. I could give you a example set of streets if you think this could help but the only solution would be IMHO finding the intersections of the streets and ask GMaps the directions. – John W. Nesk Mar 09 '13 at 23:17
  • geocodezip, do you know a way to accomplish this via the API? – John W. Nesk Mar 10 '13 at 16:48
  • The only way I know is in my answer (the "manual" option). Get driving directions between the bus stops (with them as waypoints), adding additional waypoints if necessary to make the route follow the correct roads. If you were to provide an example route (with the locations of all the stops), I can see if that is actually doable and perhaps provide an example. – geocodezip Mar 10 '13 at 17:02
  • Here is an example set: http://pastebin.com/MXhn0mDV All these streets are from the city of Recife - Pernambuco, Brazil – John W. Nesk Mar 10 '13 at 18:04
  • Here is an [example with those stops](http://www.geocodezip.com/v3_directions_multipleWayPts_CustomMrkrs_busRoute.html). As you mentioned those geocode to the "middle of the street", not where the actual bus stop is. You might be able to refine it if you provide cross streets or coordinates. – geocodezip Mar 10 '13 at 18:58
  • I think I'll try openstreetmap to find those coordinates automatically and then use on GMaps. I dont have any experience on it but I think its possble. I'll post here if I have any progress. – John W. Nesk Mar 10 '13 at 22:09
  • Are the routes available on OpenStreetMap? If so, you might be able to export the complete polyline (but it might not line up with the streets on Google Maps. – geocodezip Mar 10 '13 at 22:11
  • I made the algorithm to read the OSM xml but like you suggested there were streets that aren't available on OSM yet, so I think this task its not possible at all – John W. Nesk Mar 16 '13 at 20:13
  • I think the closet you are going to come is to manually determine the coordinates (or the closest street address) of the bus stops, then use something like [my example](http://www.geocodezip.com/v3_directions_multipleWayPts_CustomMrkrs_busRoute.html) (note that I have change some of the stops to make the route somewhat shorter, but it still looks like the stops are not quite right). I was playing with it the other day and saw what you meant by the DirectionsService using the "middle of the street", if it only has the street name. – geocodezip Mar 16 '13 at 20:18
  • Yes you are right, but there are about 400 bus lines here in my city, its too much work to be done manually. I got pretty close to solving it using OSM, the algorithm was able to find the crossroads and get its coordinates but there are streets which are not in the map yet, so it may require manual intervention to complete the route. In the other hand, Google Maps is very accurate, if they allowed users to export the map.. – John W. Nesk Mar 16 '13 at 21:45
  • If I can get the coordinates where the buses stops do you think it would help at all? The problem that the DirectionsService use the middle of the street would remain – John W. Nesk Mar 23 '13 at 01:28
  • I think if you can get the coordinates of the bus stops it would solve the problem (at least for the most part, it is still possible the DirectionsService will pick the "wrong" route, but I think it would be a lot closer). – geocodezip Mar 23 '13 at 05:14
  • I gave up :( its just not possible. I managed to manually get the coordinates of one route stops to test but there are big parts of the route that dont have stops and the DirectionsService went really wrong on that parts. I guess there is no other way but to manually determinate the route. Do you have any advice on a practical way to do this? I mean maybe to define some tags on the map being the streets and just simply link them to make the path. – John W. Nesk Mar 29 '13 at 17:29
  • 3 thoughts: 1. if you have the stops, but the route isn't correct, add additional (non-stop) waypoints to force the route to go the correct way. 2. Have someone ride the bus from beginning to end of each route capturing the GPS coordinates (with a cell phone or a GPS device), refine that data to get the route. 3. Lobby the local transit authority to [release their bus route data to google](http://maps.google.com/help/maps/mapcontent/transit/) so they can provide it as part of the transit part of the directions API. – geocodezip Mar 29 '13 at 17:44
  • I guess I'll try #3 then #1 if I have no choice. But #2 its a pretty good idea, the platform could be crowdsourced. If I ever release this I'll remember to give you the credits for helping so much – John W. Nesk Mar 29 '13 at 19:34
  • I made this to draw de route more easily, it may be useful to someone: http://seth.webege.com/interactiveroute.html You click to add a marker and every marker links to the last one, you can drag the markers to edit the route – John W. Nesk Mar 31 '13 at 04:10
  • Is there any way thru API to get the bus names with bus stops between two places which Google Maps Provides ... – Srinivas08 Oct 04 '17 at 17:14