Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle maps api v3 draw polyline
    primarykey
    data
    text
    <p>I'm new in javascript so i have problem with drawing polyline on my map. I'm receiving coordinates from GPS in vehicle and i want to draw car movement. So for i put markers on the places my car passed, but i'm not sure how to add polyline. Can anybody help me?</p> <p>I've written this so far:</p> <pre><code> var map; var markers=[]; var timeout=5000; var interval=null; function init2(){ var myLatlng = new google.maps.LatLng(45.7997016667,15.97143); var mapOptions = { zoom: 14, center: myLatlng, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL }, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); update_markers(); } function update_markers(){ console.log('update...'); for(var x in markers){ markers[x].setMap(null); } markers=[]; $.getJSON('/get', function(d){ var l=d.length; for(var x=l-5;x&lt;l;x++){ var f1=parseFloat(d[x].lat); var f2=parseFloat(d[x].long); if(f1&gt;100){ continue; f1=f1/100.0; f2=f2/100.0; } markers.push(new google.maps.Marker({ position: new google.maps.LatLng(f1, f2), map: map, title: d[x].time })); } } ); interval=setTimeout(update_markers, timeout); } google.maps.event.addDomListener(window, 'load', init2); $(function(){ $('#timeout_sel').change(function(){ clearTimeout(interval); timeout=$(this).val(); update_markers(); }); }); </code></pre> <p>And i don't know how to put this into my code:</p> <pre><code> function initialize() { var myLatLng = new google.maps.LatLng(0, -180); var mapOptions = { zoom: 3, center: myLatLng, mapTypeId: google.maps.MapTypeId.TERRAIN }; var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); var flightPlanCoordinates = [ new google.maps.LatLng(37.772323, -122.214897), new google.maps.LatLng(21.291982, -157.821856), new google.maps.LatLng(-18.142599, 178.431), new google.maps.LatLng(-27.46758, 153.027892) ]; var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, strokeColor: '#FF0000', strokeOpacity: 1.0, strokeWeight: 2 }); flightPath.setMap(map); } google.maps.event.addDomListener(window, 'load', initialize); </code></pre> <p>Can you give me some tips? The second code is from google examples and it uses fixed latlng, how do i add this in may update_markers function so it uses the same coordinates as marker? </p> <p>EDIT:</p> <pre><code> var map; var markers=[]; var timeout=5000; var interval=null; var flightPlanCoordinates=[]; function init2(){ var myLatlng = new google.maps.LatLng(45.7997016667,15.97143); var mapOptions = { zoom: 14, center: myLatlng, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL }, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); update_markers(); } function update_markers(){ console.log('update...'); for(var x in markers){ markers[x].setMap(null); } markers=[]; $.getJSON('/get', function(d){ var l=d.length; for(var x=l-5;x&lt;l;x++){ var f1=parseFloat(d[x].lat); var f2=parseFloat(d[x].long); if(f1&gt;100){ continue; f1=f1/100.0; f2=f2/100.0; } markers.push(new google.maps.Marker({ position: new google.maps.LatLng(f1, f2), map: map, title: d[x].time })); flightPlanCoordinates = new google.maps.LatLng(f1,f2); } var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, strokeColor: '#FF0000', strokeOpacity: 1.0, strokeWeight: 2 }); } ); interval=setTimeout(update_markers, timeout); } google.maps.event.addDomListener(window, 'load', init2); $(function(){ $('#timeout_sel').change(function(){ clearTimeout(interval); timeout=$(this).val(); update_markers(); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload