var infowindow = new google.maps.InfoWindow({ content: "Loading" }); var overlay; var location; var mapOptions = {
zoom: 1, center: new google.maps.LatLng(0, 0), mapTypeId: 'hybrid' }; var gmap = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var marker;
function initialize() { console.log("This is a test log"); marker = new google.maps.Marker({ position: new google.maps.LatLng(0, 0), map: gmap }); marker.addListener('click', function() { infowindow.open(gmap, marker); });
setInterval(logSeen, 5000);
setInterval(getLocationInfo, 1000); getLocationInfo(); gmap.zoom = 14;
infowindow.open(gmap, marker);
}
function logSeen() { var http = new XMLHttpRequest();
http.open("POST", "findme/set_seen.php", true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//Creating an alert box with the content that the php file echo out http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { //Checking if the respose text contain something if (http.responseText.trim() != "") { console.log(http.responseText); //console.log(new Array(JSON.parse(http.responseText))[0]);
} } }; //Sending the parameters over to the php file var url = new URL(window.location.href); var code = url.searchParams.get("code"); http.send("code=" + encodeURIComponent(code)); }
var count = 4; function getLocationInfo() { ++count; if (count == 5) { count = 0; //Creating a XMLHttp request var http = new XMLHttpRequest();
//Opening the connection to the php file http.open("POST", "findme/get_location_info.php", true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//Creating an alert box with the content that the php file echo out http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { //Checking if the respose text contain something if (http.responseText.trim() != "") { reloadInfo(new Array(JSON.parse(http.responseText))[0]);
} } }; //Sending the parameters over to the php file var url = new URL(window.location.href); var code = url.searchParams.get("code"); http.send("code=" + encodeURIComponent(code)); } else { updateText(); } }
function updateText() { var timeSinceLastUpdateString = "Sidst opdateret: "; var lastDate = date * 1 + count * 1; var hours = Math.floor(lastDate / 60 / 60);
lastDate -= 60 * 60 * hours; var min = Math.floor(lastDate / 60); lastDate -= 60 * min; var sec = lastDate;
var hourText = "Timer"; if (hours == 1) { hourText = "Time"; } var minText = "Minutter"; if (min == 1) { minText = "Minut"; } var secorndText = "sekunder"; if (sec == 1) { secorndText = "Sekund"; } if (hours > 0) { timeSinceLastUpdateString += hours + " " + hourText + " " + min + " " + minText + " " + sec + " " + secorndText; } else if (min > 0) { timeSinceLastUpdateString += min + " " + minText + " " + sec + " " + secorndText; } else { timeSinceLastUpdateString += sec + " " + secorndText; }
infowindow.setContent(timeSinceLastUpdateString + "
" + (Math.floor((speed * 3.6)* 100) / 100) + "km/t");
}
var lati = 0; var long = 0; var speed = 0; var date = ""; function reloadInfo(values) { if (values == null) { window.location.replace("https://hereiam.app/expired"); } lati = values[0]; long = values[1]; speed = values[2]; date = values[3];
updateText();
marker.setPosition(new google.maps.LatLng(lati,long));
gmap.setCenter(new google.maps.LatLng(lati, long)); }


