I'm developing rails app, which use google maps and paint car routes.
I use gmaps4rails
gem for drawling line on a map,
So, I have a plan for car ( array of coordinates for car route by plan ) and report for car ( array of coordinates for car route which was actually drove ).
So, I have to arrays of coordinates - plan and report, example with random points :
@plan = [ [12.124, 12,34253], [11.124, 12,34253], ... [8.124, 5.344] ]
@report = [ [12.224, 12,64253], [10.124, 12,34253], ... [9.124, 6.345] ]
I know how draw one line on map, for example this is view with 'plan' line on map:
%div.container
%div.panel.panel-default.col-sm-9
%div.panel-body.row
#map.col-sm-12
:javascript
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
polyline = #{raw @plan.to_json}
handler.addPolyline(polyline); // and not addPolylines
handler.bounds.extend(polyline[0]);
handler.bounds.extend(polyline[ polyline.length - 1]);
handler.fitMapToBounds();
});
But now I need to draw 'plan' line and 'report' line on the same map. How can I draw two lines with different colors on the same map?
Thanks kindly.
There is an error in your code, gmaps4rails expects an array of objects providing
lat
andlng
properties. The transformation is quite easy though.Concerning the options, you can pass them as a second argument. Source code is meant to be very clear.
Anyway, Here is a working plunkr with your data