Tôi chỉ cần cập nhật điểm đánh dấu khi thiết bị đang di chuyển hoặc khi thiết bị nhận được độ chính xác cao hơn. Khi thay đổi vị trí cũng tải lại bản đồ và tôi chỉ cần di chuyển nhà sản xuất. Tôi có mã sau:Vị trí địa lý: chỉ di chuyển điểm đánh dấu bản đồ google mà không cần tải lại bản đồ
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.");
}
Cảm ơn!
Bạn cũng có thể thấy hữu ích này. http://google-maps-utility-library-v3.googlecode.com/svn/trunk/geolocationmarker/docs/reference.html –