I have the following code, which obtains the coordinates of a database and creates the marker on a map, but I want to "join the markers" using polylineas, but to do it alone, according to the order in which the markers are obtained. coordinates. In the following code only the markers are created on the map but not the lines
<script type="text/javascript">
var locations = [],
map,
center = new google.maps.LatLng(locations),
poly,
ruta = Array();
function initialize() {
@foreach (RutaRastreo ruta in Model.RutaRastreo){
if (ruta.Gps_Latitud != 0 && ruta.Gps_Longitud != 0){
@:locations.push([@ruta.Gps_Latitud, @ruta.Gps_Longitud]);
}
}
map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(locations),
});
var marker,
i,
bounds = new google.maps.LatLngBounds();
for (i = 0; i < locations.length; i++) {
ruta[i] = new google.maps.LatLng(locations[i], locations[i]);
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][0], locations[i][1]),
map: map
});
bounds.extend(marker.position);
drawPath();
}
map.fitBounds(bounds);
}
}
initialize();
console.log(ruta);
function drawPath() {
new google.maps.Polyline({
path: ruta,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1,
strokeWeight: 4,
map: map
});
}
</script>
The results of making console.log (route) are shown in the console;