Is there a way to move a marker or recenter the map without redrawing the entire map?
I am using this code
var markerLat = 39.0
var markerLon = -80.0;
var centerLat = 39.0;
var centerLon = -80.0
var myZoom = 15;
function initMap() {
// The location of Uluru
const uluru = { lat: centerLat, lng: centerLon };
// The map, centered at Uluru
const map = new google.maps.Map(document.getElementById("map"), {
zoom: myZoom,
center: uluru,
});
// The marker, positioned at Uluru
var myLatlng = new google.maps.LatLng(markerLat,markerLon);
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
});
}
window.initMap = initMap;
let eventSource = new EventSource("/sseTest");
eventSource.onmessage = function(event) {
console.log("new message from index.js " + event.data);
const myArray = event.data.split(" ");
if(myArray[0] == 0) {
markerLat = myArray[0];
markerLon = myArray[1];
} else {
markerLat = myArray[2];
markerLon = myArray[3];
}
const myMarkerLatlng = new google.maps.LatLng(markerLat, markerLon);
const myCenterLatLon = new google.maps.LatLng(markerLat, markerLon);
var mapOptions = {
zoom: myZoom,
center: myCenterLatLon,
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var marker = new google.maps.Marker({
position: myMarkerLatlng,
map: map,
});
marker.setMap(map);
};
and it seems to redraw the map like an entire page refresh when an update (once a minute) comes in. I would like it to simply move the marker like it does when a user is sharing their location with you.