1

I need to draw multiple routes on a google map. By googeling around i found 2 solutions. 1 was to create and render each route in a sepparate DirectionsRenderer object. The other solution (which i have found here) suggests storing the polygons in a array and draw them out all at once (which seems like a better solution to me)

The problem is, i am unable to find a way to get all the polygons on the map. Does anyone has a snippet of code on how to do this?

Community
  • 1
  • 1
Arxae
  • 102
  • 2
  • 9

1 Answers1

1

I'm using the first solution. here is my code.

var map;
var polyGidis;
var polyDonus;
var pozsGidis = [];
var pozsDonus = [];
function init() {
   var myOptions = {
      zoom: 5,
      center: new google.maps.LatLng(39.00, 35.00),
      mapTypeId: google.maps.MapTypeId.ROADMAP
   };
   map = new google.maps.Map(document.getElementById('divMap'), myOptions);
   polyGidis = new google.maps.Polyline({ strokeColor: 'black', strokeOpacity: 0.8, strokeWeight: 2, map: map, zIndex: 100 });
   polyDonus = new google.maps.Polyline({ strokeColor: 'red', strokeOpacity: 0.8, strokeWeight: 6, map: map, zIndex: 80 });

   var polyPathGidis = polyGidis.getPath();
   var polyPathDonus = polyDonus.getPath();

   for (var i = 0; i < pozsGidis.length; i++) {
      polyPathGidis.push(new google.maps.LatLng(pozsGidis[i].lat, pozsGidis[i].lng));
   }
   for (var i = 0; i < pozsDonus.length; i++) {
      polyPathDonus.push(new google.maps.LatLng(pozsDonus[i].lat, pozsDonus[i].lng));
   }
}
Özgür Kara
  • 1,333
  • 10
  • 22