Save routes in database

4,050 views
Skip to first unread message

azuro

unread,
Sep 20, 2010, 8:17:19 PM9/20/10
to Google Maps JavaScript API v3
Hello,

I'm setting up a web application that allow user to input their origin
and destination address. Then, Google Map will display the suggested
route from the origin to the destination. On the map, I'll allow user
to drag their preferred route and I'd like to save the user selected
route in a database (MSSQL) so when the user comes back to the page,
Google Map will show them their customized route.

How do I save the JSON formatted object from Google Map
(DirectionResult object) to the database? I'm doing this in .NET 4.0.

Also, Google map does not display when I declare the map canvas div
within the form tag. Anyone know what the issue was?

Thanks so much!

Jay

David Violette

unread,
Oct 5, 2010, 2:54:40 PM10/5/10
to google-map...@googlegroups.com
Did you find an answer to saving in database yet? I am looking for same type solution.


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


JKurtock

unread,
Oct 5, 2010, 5:26:34 PM10/5/10
to Google Maps JavaScript API v3
Don't bother trying to save the directionResult. All you need is to
save the user entered waypoints (you already have those), PLUS the
waypoints created by Google when the user dragged the route. The
waypoints created by dragging are an array of objects found in
currentDirections.routes[0].legs[0].via_waypoint[]. The objects have
attributes location, step_index and step_interpolation; all you'll
need is location if the user entered only a start and end (because all
the via_waypoints will be between the start and end).

When re-displaying the saved route, the request to the
directionsService will include the waypoints property (referred to in
the documentation as "intermediate" waypoints). Since you are using
the "same" waypoints, you will get the same route.

In the "free" API you are limited to 8 intermediate waypoints to the
directionsService, yet the user is allowed to create more than 8
"vias" by dragging. To work around this just remember that directions
are "transitive" (A>B>C is the same as A>B followed by B>C), and break
the route into as many segments as needed to avoid exceeding 8
intermediate waypoints.

The via_waypoint does not appear to be documented, which means that it
could suddenly disappear. You've been warned.

(Then, of course, you have to send the retrieved waypoints back to
your server to get them into the database, and retrieve waypoints from
the database to generate the new page, but you probably have that part
completed already.)

On Oct 5, 11:54 am, David Violette <davidaviole...@gmail.com> wrote:
> Did you find an answer to saving in database yet? I am looking for same type
> solution.

Reply all
Reply to author
Forward
0 new messages