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
Related
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.
If I make a request via javascript, I get a JSON object returned that has Routes, Legs, Steps ,and Path data, the latter being a set of Lat,Lng co-ordinates along the step.
https://maps.googleapis.com/maps/api/js?...query for the javascript and then using the directionsService function
If I make a request server-side, with exactly the same request, I only get Routes, Legs and Steps data returned, no Path data.
https://maps.googleapis.com/maps/api/json?...query
Has anyone else experienced this? are there any workarounds? Uisng the other URL in each application just returns a 404.
You can extract path data from the polyline property of the step:
polyline contains a single points object that holds an encoded polyline representation of the step. This polyline is an approximate (smoothed) path of the step.
https://developers.google.com/maps/documentation/directions/intro#DirectionsResponseElements
Encoded polyline algorithm is described here:
https://developers.google.com/maps/documentation/utilities/polylinealgorithm
Google Maps JavaScript API has a static method in geometry library to decode the encoded polyline:
https://developers.google.com/maps/documentation/javascript/reference#encoding
For Android apps you can use Google Maps Android API utility library that contains polyline decoding and encoding functions:
https://github.com/googlemaps/android-maps-utils
Google Maps iOS SDK also has static method to obtain a path from encoded polyline:
https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_path
Hope it helps!
I read in the documentation that using polyline, I just have a straight line between two points. And if I use Routes (direction service), I don't have the straight line, but a real route between this two places (points).
Not exactly. Polyline means you give a list (array) of points; the polyline follows those points (with a straight line from one point to the next).
If you only give the start and end point, then yes, it will be a straight line (still following the curve of the earth).
You can request a route, read the waypoints of the route and make (draw) a polyline that follows the exact route.
The only reason you would do this, is because you have much more control over the polyline than over the standard route that Google draws.
Example: with a polyline, you can easily set onClick events on that polyline; it's a harder to do this with the standard route
What I need is the following.
Whenever I add any instance of object in my website, I need the server to add the location of the object to my own map either in Google maps or Bing maps (Bing maps docs are more clear therefore I'm going to use Bing).
Later, whenever I view the object in my site, the map should point to the location of the object and other my map objects in the same map.
How can this be achieved? Do I need to hold all the coordinates and object descriptions in my server, or somehow it is saved in the google or bing.
I went through the docs, but couldn't find any information I need.
You need to store them on your server and load them into the map on your webpage. There are ways with both google (fusion tables) and bing (spatial data services) of storing them with the provider but if you are already storing a copy for your website you are better off keeping them there for the map rather than maintaining two copies.
I'm not sure how technical you are but this best architecture approach is this:
1) Write a database query that finds objects to show on your map, ideally filtered by whatever the user can use to filter objects elsewhere on your site. Add to this query a filter by geographical bounding box (the range of latitude and longitude that can be seen on your map at any one point). The bounding box filter is just a simple sql BETWEEN clause but will mean you dont have to load every single object on to the map.
2) write a "webservice" that uses the database query in 1) and turns the results into JSON. This approach will lead to a much cleaner seperation between your mapping code in javascript and your server side code in the webservice.
3) Write your mapping frontend in Bing using javascript and use something like Jquery to read data from the webservice as the map is moved around re-load data that know should be shown on the new map view. As the data will be in JSON its much easier as JSON will just give you javascript versions of your objects
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