1
Good morning guys, I need the code below besides drawing the lines on the map, remove the lines drawn earlier, but I’m not getting, someone could give me a help?
Follow image with result of current code
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="https://code.angularjs.org/1.2.12/angular.min.js.map"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MINHAAPI"></script>
<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script>
<style type="text/css" media="screen">
#map {
position:absolute;
top: 0; bottom: 0; left: 0; right: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
$(document).ready(function(){
var MAP_ZOOM = 15
var MARKER_SIZE = 60
var map = new google.maps.Map(document.getElementById('map'), {
zoom: MAP_ZOOM,
center: {lat: -12.17011059, lng: -44.8119901,},
mapTypeId: 'satellite'
});
var markers = [];
window.onmessage = function(evt){
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
var latlng = JSON.parse(evt.data);
var array = $.map(latlng, function(el) {
return [[el.lat, el.lng]];
});
var data = JSON.parse(evt.data);
map.setZoom(MAP_ZOOM);
map.setCenter({lat:latlng[0].lat,lng:latlng[0].lng});
markers = data.map(function(el, i) {
var marker = new google.maps.Marker({
position: el,
icon: {
url: el.iconUrl,
scaledSize: new google.maps.Size(MARKER_SIZE, MARKER_SIZE)
},
map:map
});
if (i > 0) { // move this inside the marker creation loop
var sitepath = new google.maps.Polyline({
// use the markers in for the coordinates
path: latlng,
geodesic: false,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2,
map: map
});
}
google.maps.event.addListener(marker , 'click', function(){
var infowindow = new google.maps.InfoWindow({
content:el.description,
position: el,
maxWidth: 200,
});
infowindow.open(map);
setTimeout(function () { infowindow.close(); }, 120000);
});
return marker
});
}
});
</script>
</body>
</html>
Well, I’m new to Javascript and HTML I understand only the basics, I made the changes in the code but I don’t know if I changed in the correct way, I believe that not because it remains the same ...
– Jeferson Heinrich
Please send me your code the way you changed it, so I can help you better
– Luis Faconi
did not fit all the code in the answer, follows code in another answer
– Jeferson Heinrich