how to display multiple polylines from directions in google maps?

i want to draw multiple polylines on the google map, for multiple routes. for this i am using google.maps.DirectionsService

function drawPolyline(source,destination,waypoints){ // show route between the points directionsService = new google.maps.DirectionsService(); directionsDisplay = new google.maps.DirectionsRenderer( { suppressMarkers: true, suppressInfoWindows: true }); directionsDisplay.setMap(map); var request = { origin:source, destination:destination, waypoints:waypoints, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); }

but when i call this method multiple times, only last polyline is appearing. and i want different colors for different polylines.

-------------Problems Reply------------

Directions lets you inspect the route:

The DirectionsResult object has and array of routes[], which allows you to get a set of encoded polylines that makes up the route:

if (status == google.maps.DirectionsStatus.OK)


You can use the routes[] array to construct Polyline overlays as Scottux mentioned.

You need to use a polyline for each, not a directions renderer.

var line = new google.maps.Polyline({clickable:true,map:map,path:"some lat,lngs"});

Please look at the api here: Options are listed here:

The DirectionsRenderer isn't very flexible for drawing lines, it is simply a helper for simple direction functionality.

Category:google maps Views:1 Time:2012-01-12

Related post

  • Multiple polylines and infowindows with Google Maps V3 2010-11-01

    I have a map with multiple polylines and would like to open a line-specific-infowindow when clicking the line. So far my code only shows the content of the last iteration. I found two very nice examples of what I want but after hours of trying I am s

  • Changing the Multiple Polyline stroke color on google map v3 2012-01-24

    I need to create multiple polylines ,each with its own color, and their markers are connected to each other,I am using google map v3. For example,I have five markers and they are all the connected to each other through red color polylines. Now I want

  • Multiple markers with labels in Google Maps 2011-01-21

    I'd like to implement multiple markers with labels (documented here: and I'm having some problems with writing the code. For 2 markers for example

  • Set Direction with Google Map URL code for BlackBerry and Windows Phone 7 2012-01-13

    I know that we can open the map and set the direction from source to destination by using the following URL:,72.44445&daddr=23.55555,72.55555 But I noticed that this URL only works in iPhone and Android.

  • I am unable to print map directions from Google map. 2013-01-25

    I am unable to print map directions from Google map. Directions docutment just sits in que and will not print. Yet, I can print a "test" page and it DOES print. Any suggestions on how to get my map directions page to print? Mod moved: <Internet Ex

  • Iterating through a JSON file to display multiple polylines 2012-01-01

    I am trying to render a map with multiple polylines that are pulled from an external JSON resource. Each JSON record has a number of descriptive fields as well as a field containing an array of LatLngs. The code seems to get the JSON data just fine a

  • Android: Draw direction in google map 2010-02-01

    I've been busy for a long time finding out how to draw a line between two (GPS) points on the map in HelloMapView but with no luck. Could anyone please tell me how to do so. Suppose I use the HelloMapView which extends MapView. Do I need to use overl

  • MyAnnotation view multiple lines text in iphone google map 2010-10-08

    MKCoordinateRegion region1; = 50.366772; = 20.010607; region1.span.longitudeDelta = 0.01f; region1.span.latitudeDelta = 0.01f; MyAnnotation *ann1 = [[MyAnnotation alloc] init]; ann1.title = @"Text1"; a

  • Change default markers for directions on google maps 2011-06-27

    I'm a complete noob with google maps api and I started with a given script that I'm editing to what I need to do. In this case I have a map with some points in it that come from a database. They are like this (after I get the lat/lng from the databas

  • Handling multiple routes with waypoints in Google Maps v3 2012-04-13

    I want to display multiple directions with dragable waypoints and save each waypoints associating with origin, destination in object or database whenever Route.prototype.setWayPoints() is called. This guy is doing that with single route with dragable

  • Providing simple address/driving directions with Google Maps 2009-04-06

    I have been pouring over the Google Maps API information, and for the life of me I can't seem to find an example, or figure out the exact right way of doing what I want. From a simple HTML layout I need to display a Google Map, with a single address

  • Show wind direction on Google Maps 2010-02-17

    I calculated the wind direction and now I want to show the wind direction pointing to 144 degrees (on compass). How can I show this arrow on Google Maps? --------------Solutions------------- In order to show an arrow over a google map you can create

  • Fetching multiple coordinates from database for Google Maps using CodeIgniter 2011-07-09

    i am trying to get multiple latitude and longitude values from database and plot a google map. i have around 460 different locations in my database with their name, latitude and longitude values. I need markers for all of those values at once when th

  • How to get street directions in google map 2012-02-15

    I want to display street directions from my current location to particular known location(latitude and longitude), how to do it using google map? --------------Solutions------------- you can do that till android 1.6, they have removed the street dire

  • how to add google Directions in google maps 2012-02-28

    The current code retrieves all info, displays all markers on a map and if a marker is clicked, infowindow renders showing its content. What i want to do is that i want to implement directions in this. How can i add directions in my code so that it wi

  • Get routes and directions from Google Maps without using Javascript? 2009-06-04

    So, if you are writting an application -not a website- and you need to resolve the directions from one location to another, how can you get the information from Google Maps without using Javascript? I am wondering if there's any set of special URL or

  • How to get markers after calling drive directions in Google Maps API? 2010-03-12

    I just started working using Google Maps API yesterday, and trying to set up drive directions to my map. My problem is: when I call the function load, // [...] gdir = new GDirections(map, directionsPanel); // [...] gdir.load("from: " + fromAddress +

  • Multiple markers not showing in Google Maps with Javascript API v3? 2010-04-03

    I'd like to know how to put multiple markers for Google Maps using Javascript API v3. I tried the solution posted here, but it does not work for me for some reason: var directionDisplay; function initialize() { var myOptions = { zoom: 9, center: new

  • Display the info window of a Google map marker 2010-05-28

    I have succeeded in loading a Google map using the gMap jQuery plugin and making it display several markers passed to it in a JSON object using the pattern demonstrated here under "Map with marker and info window". So far, so good. Now I want to have

Copyright (C), All Rights Reserved.

processed in 0.101 (s). 11 q(s)