57
rated 0 times
[
59]
[
2]
/ answers: 1 / hits: 24367
/ 11 Years ago, thu, april 25, 2013, 12:00:00
I need to update only the marker when the device is moving or when the device is getting more accuracy. When the position change also reload the map and I need to move only the maker. I have the following code:
if (navigator.geolocation) {
navigator.geolocation.watchPosition(
function(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var accuracy = position.coords.accuracy;
var coords = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
zoom: 20,
center: coords,
streetViewControl: false,
mapTypeControl: false,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var capa = document.getElementById(capa);
capa.innerHTML = latitud: + latitude + longitud: + aquesta es la precisio en metres : + accuracy;
map = new google.maps.Map(
document.getElementById(mapContainer), mapOptions
);
var marker = new google.maps.Marker({
position: coords,
map: map,
title: ok
});
},function error(msg){alert('Please enable your GPS position future.');
}, {maximumAge:0, timeout:5000, enableHighAccuracy: false});
}else {
alert(Geolocation API is not supported in your browser.);
}
Thanks!
More From » html