OSRM route directions - gis

Here is what I am trying to do. I have a pair of lat, lngs and I am trying to find the route between the pair of lat, lngs using OSRM. I extracted polylines from each step object using the OSRM route service output but couldn't figure out how to extract the direction for each step. How do I get the direction for each step?

See the API documentation for parameters to modify the response.
Passing steps=true will return RouteStep objects. A RouteStep contains the information you are looking for, i.e. StepManeuver objects, Lane objects and Intersection objects as well as distance and duration.

https://github.com/Project-OSRM/osrm-text-instructions should help. It's a nodejs application. I've wrapped it into an api; Now after fetching the directions from OSRM, I call the directions api and get the text directions.

Related

Can we use overview_polyline into waypoints of particular route duration

I am using google direction service API to get route and it's distance with route drag option.
For example if i create a route between A & B. then i have dragged the original google given path to my own.
then i need to save my custom route (dragged route) and show the future reference.
In that case can i use overview_polyline (direction response json node value) into waypoints to show exact my custom route.
Please help me
Sure, you can store the overview_polyline and later use it to draw a polyline which will restore your customized route.
To do this you will need a geometry library and call a google.maps.geometry.encoding.decodePath() method to get the array of your points.
After that you can use this array to construct a Polyline object.
Please have a look at this sample code:
http://jsbin.com/kijaze/1/edit?html,output

Display Google Map API route on map

I am new to google Map Api V3, and i am planning to find the best route among some waypoint.
I found that the direction API could solve my problem (http://maps.googleapis.com/maps/api/directions/json?...)
I got the Json output, but is there any way to display the route on Google map directly?
Or i should parse the Json, get the legs information, and plot it again??
Thanks a lot

Google Directions API not providing exact steps

I'm using Google Directions API to get directions between 2 locations. I'm able to get the Webservice response (json) and draw a line over the map.
However, I noticed that the direction steps are quite less in the response thus making the lines not follow exact road curves. This is for any location, for example.
When I search the locations on Google Maps, I can see lines drawn exactly over road curves.
The steps received in the Webservice response are the turn points where the user's direction will change.
I now tried to get the polyline from the webservice response and extracted coordinates with code provided here. Problem resolved!

What states does my route travel through?

I've got a page that has a map with a starting and ending location. I run a route between them to get the nifty line showing the route. I'm currently using Bing but have attempted with Google as well. I'd like to know which states this route passes through so I can then overlay those states with specific information.
Any suggestions on how to obtain this would be most appreciated.
I'm using the AJAX SDK's for both Bing and Google. Handling all the local stuff with js/jquery.
You can use a reverse geo-code request on the Google Maps API to determine what state a particular point is in. So I imagine you could process your array of points returned with the directions request and pull out the state for each one.
In the v2 API, this would be:
results.AddressDetails.AdministrativeArea.AdministrativeAreaName
I think this is a bit more intuitive in v3. You can examine the AddressComponents array in the results to find the appropriate type:
{
"long_name":"California",
"short_name":"CA",
"types":["administrative_area_level_1","political"]
}
You could optimize the reverse geocoding by using divide and conquer on the array of positions on the route (if the state is the same for the first and middle position, then don't do reverse geocoding on the intervening points).
The MapQuest Directions web service has a stateBoundaryDisplay flag that will explicitly put state boundary crossings (ie "Crossing into statename") in the narrative. You could easily pull just that info from the json/xml response with a text search of the narrative steps.
http://www.mapquestapi.com/directions/#advancedoptions
Hope that helps.
Roman
You could create your own service utilizing a shapefile and a library like SharpMap or a geodatabase like mysql spatial, sql server spatial, etc. Then you simply just need to run an intersection query to discover which states your route runs through. This approach would work for any polygon set, so you could easily extend the solution to counties, voting district, school districts, etc.

Getting coordinates and names for a driving route

Is there any way to get the geo coordinates for a driving direction from Google Maps API?
if we use URL to show the driving direction with source and destination address we'll get the map and route as an webpage, instead of that I like to get the co-ordinates and details in some XML like format.
Sure, see the docs. You make a GDirections object (without a div AND without a map so nothing will be displayed by default and you'll handle all the displaying), and call its load method, specifying getPolyline and getSteps as both true (so you'll get the polyline and the textual directions despite the lack of div and map).
The GDirections' object load event fires when the results are ready. Then you use getPolyline, getNumRoutes, and getRoute methods on the object to retrieve results.
As a full reference, also check this (both GDirections and GDirectionsOptions)...!
The Google API documentation has a section on XML requests and parsing. It's quite detailed, many options available.
Hai all,
Finally i got the solution, google also provides the driving directions in JSON format, we can parse the JSON data and that will give all the details including coordinates, name, description, distance and approximate time
example:
http://maps.google.com/maps/nav?key=YOUR-MAP-KEY&output=json&q=from:sourceAddress to: destinationAddress
Thank you all for the support