https://s30.postimg.org/my0tsomb5/Screenshot_from_2017_01_28_16_13_26.png
function getPos() {//initial function to read the position
estado = "livre";
navigator.geolocation.getCurrentPosition(
onSuccess, onError, {enableHighAccuracy:true});
setTimeout(keep_alive, 1000); //read every 1 seconds
}
function onSuccess(position) {//read map and mark it in the map
lat = position.coords.latitude;
lon = position.coords.longitude;
console.log("Found - LAT: ", lat, "LON: ", lon);
var mapoptions = {
zoom: 16,
center: new google.maps.LatLng(lat,lon),
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
map = new google.maps.Map(document.getElementById("map"), mapoptions);
var image = {
url: 'try.png',
scaledSize : new google.maps.Size(50, 60)
};
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lon),
map: map,
icon: image,
});
//save_position();
}
function onError(error) {
console.log('code: ' + error.code, 'message: ' + error.message);
}
function keep_alive() {//read position and mark it in the map
navigator.geolocation.getCurrentPosition(onRefresh,
onError, {enableHighAccuracy:true});
//save_position();
setTimeout(keep_alive, 1000); //read every 1 seconds
}
//refresh only the marker
function onRefresh(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
console.log("Found - LAT: ", lat, "LON: ", lon);
marker.setPosition(new google.maps.LatLng(lat, lon));//refresh marker
map.setCenter(new google.maps.LatLng(lat, lon));
//resfresh center of the map
}