multiple routes on map?

7,038 views
Skip to first unread message

Jon Grubb

unread,
Mar 8, 2010, 7:27:19 AM3/8/10
to Google Maps JavaScript API v3
Hi folks. I'm building a web site for a non-profit rescued pet
transport group called "On The Road Again"(OTRA) Pet Transport. Using
V3 for map rendering. Site is http://otrapettransport.org/ . Home page
pulls up a map of the US. Notice that there is a green route showing a
transport from Huntsville, AL to Boston, MA. Unfortunately, there are
actually TWO routes. There is a blue route from Bakersfield, CA to
Vancouver BC that doesn't get displayed - unless you stop the display
loop after the first loop, then it gets displayed. Display loops are
in a the "maps.js" file.

What is the mechanism I should be using to display multiple routes on
one map? Did I miss something in the reference? Also, I,m rendering
the routes anew every time the map is refreshed. I intend to
eventually store the JSON routes (DirectionsService results) in a
MySQL blob and then retrieve and display them rather than having
Google recreate them every time the map comes up.

V3 is a VERY nice package. Keep up the good work. Thanx...

Susannah (Google Employee)

unread,
Mar 8, 2010, 7:17:56 PM3/8/10
to Google Maps JavaScript API v3
Hi Jon,

You should be able to create two DirectionsRenderer objects, each that
use the same map and different DirectionsResults.

var map = new
google.maps.Map(document.getElementById("map_canvas"));
function renderDirections(result) {
var directionsRenderer = new google.maps.DirectionsRenderer;
directionsRenderer.setMap(map);
directionsRenderer.setDirections(result);
}

var directionsService = new google.maps.DirectionsService;
function requestDirections(start, end) {
directionsService.route({
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, function(result) {
renderDirections(result);
});
}
requestDirections('Huntsville, AL', 'Boston, MA');
requestDirections('Bakersfield, CA', 'Vancouver, BC');

Hope that helps,
Susannah

Jon Grubb

unread,
Mar 9, 2010, 7:09:43 AM3/9/10
to Google Maps JavaScript API v3
YES! EXCELLENT! That worked. Thank you very much. I understand what I
need to do.

On Mar 8, 7:17 pm, "Susannah (Google Employee)" <susann...@google.com>
wrote:

Marvin Divo

unread,
Mar 17, 2010, 10:18:24 AM3/17/10
to Google Maps JavaScript API v3
Hello Jon,

I'm planning to have a lot of routs on the map and keep asking Google
to recalculate them every time do not sound good.
I'm wondering did you succeed with your idea to keep DirectionsResult
object in MySQL. Could you share the technique/concepts? :)

Another solution I can think of is to convert (somehow)
DirectionsRoute to array of LatLng (store them in MySQL) then draw a
Polyline form that array.

Any other solutions/ideas?

Thanks.

On Mar 8, 2:27 pm, Jon Grubb <jonwgr...@gmail.com> wrote:
> Hi folks. I'm building a web site
>

> ... skipped ...

Reply all
Reply to author
Forward
0 new messages