So far I am only able to show a only single bus route when using Google Maps API v3. However on google websites, one active route and other 2-3 grayed out ones are shown.
Is there an option in the API v3 to enable alternative bus routes or do I have to custom code that feature?
How do you select directions for specific time and date in future like on google maps?
you'll need to set the provideRouteAlternatives-option of the DirectionsRequest to true, then you may(when available) get alternative routes.
To draw the multiple routes you must create separate DirectionsRenderer-instances for each route and set the index of the desired route as routeIndex-property of the DirectionsRenderer
the time(departure/arrival) may be specified via the transitOptions of the DirectionsRequest
Related
I currently have an application which takes a a start and end point from a user and sends a request to the google maps directions API, for example: https://maps.googleapis.com/maps/api/directions/xml?key=my_key8&origin=M460PU&destination=NN36NW&sensor=false&mode=driving&units=imperial&departure_time=1501752779
We then display the estimated journey time for a given route. The user has asked if it's possible for us to include a link directly to Google maps so that they can see the route on the maps and make sure it looks ok.
I've seen previous questions such as this one: Link to Google Maps but that seems to be a solution for a simple Google Maps search, where as in my case I want to see a route from the directions API.
I'm trying to figure out if I there's a way I can take the data from the Directions API response and plug that in to a http://maps.google.com/maps URL that the user can click on. Has anyone ever had any success doing this?
As mentioned #geocodezip you should use Google Maps JavaScript API or Google Static Maps API in order to show exactly the same route as the output of Directions API.
There is also an option to open Google Maps web site or native app using the Google Maps URLs. You can have a look at the documentation to figure out how to create the URL:
https://developers.google.com/maps/documentation/urls/guide#directions-action
The only issue is that the Google Maps URLs doesn't provide any parameter for departure time, so you will always get routes for "Leave now" that might have discrepancies comparing to a web service that was requested for a different departure time.
Based on your question I think the Google Maps URL might be
https://www.google.com/maps/dir/?api=1&origin=M460PU&destination=NN36NW&travelmode=driving
I have stumbled upon this: when I use directionsDisplay.getDirections() API to fetch and display the results, it works, but when I do it via json:
https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJR0FT51wiDogRNuVKiLn9ZLA&destination=place_id:ChIJMWaiY0YpTIYRRdGvCMg7m0g&key=MY_KEY&waypoints=via:place_id:ChIJaWS37r88DIgRu-ak1l7eXAQ
I get "status" : "ZERO_RESULTS"
I am wondering why this might be happening? Any ideas?
Remove the "via:" keyword from the waypoints to get the response.
https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJR0FT51wiDogRNuVKiLn9ZLA&destination=place_id:ChIJMWaiY0YpTIYRRdGvCMg7m0g&key=MY_KEY&waypoints=place_id:ChIJaWS37r88DIgRu-ak1l7eXAQ
From the documentation:
The via: prefix is most effective when creating routes in response to the user dragging the waypoints on the map. Doing so allows the user to see how the final route may look in real-time and helps ensure that waypoints are placed in locations that are accessible to the Google Maps Directions API.
Caution: Using the via: prefix to avoid stopovers results in directions that are very strict in their interpretation of the waypoint. This may result in severe detours on the route or ZERO_RESULTS in the response status code if the Google Maps Directions API is unable to create directions through that point.
So I have successfully found directions to get some lat/long A to lat/long B using the Google Maps v3 directions api.
I want to be able to take a route from this api and give the user an option to view them on the google maps website.
I dont want to show the route on my website but only show the time it would take to get from A to B.
is this possible?
thanks!
https://developers.google.com/maps/documentation/directions/#Limits
The Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited. Additionally, calculation of directions generates copyrights and warnings which must be displayed to the user in some fashion. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions.
I am new to Google map API and Phonegap. I am trying to create an app which will show the possible routes between the origin and destiny.
So is it possible to get multiple routes with direction using Google map API.
Is there any other API apart from Google which will provide me the multiple route. Thanks in advance.
The DirectionsRequest query has a boolean parameter provideRouteAlternatives that returns alternate routes in the DirectionsResult object.
Here is the documentation on working with the Directions Service:
If one puts in an address or set of coordinates into Google Maps (the web interface), it will create a set of one or more markers representing your search results on the map. You can click these markers to show an information callout that has data such as the phone number or reviews of the place.
I'd like to emulate this feature in a map on a web page I am building using Google Maps V3. I have successfully created a marker with custom icon and invoked an InfoWindow but I have to specify the content myself. Is there a way I can get the InfoWindow content for that street address/place as you would if you used Google Maps directly? I've seen a few references to the Google Places API, but I would have to extract and style the information myself which would require more time than I have in my budget. Is this the only way?
Thanks,
Steve
You need to do some reverse geocoding
http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
Here is an example:
http://code.google.com/p/gmaps-samples-v3/source/browse/trunk/io-2010-bootcamp/v3-reverse-geocode.html?r=204