0
我正在使用谷歌地圖,具體來說,我正在與http://hpneo.github.io/gmaps gps跟蹤模擬,在這裏我需要更新每個點上的位置。 在gmaps腳本中,標記存儲在一個數組上,然後我正在考慮獲取每個點並使用setPoint方法更新位置,但是gmaps腳本沒有實現此方法。我正在考慮實施這種方法,但我的問題是: 在gmaps腳本上有一個標記數組後,我如何識別每個標記以便更新正確標記上的位置012r或者我可能必須將其存儲在一個外部數組,幫助我識別每個標記的關聯數組,但我想當我更新它們時,gmap腳本上的數組也將保持在相同位置而未更新 我附上我的代碼更新位置的標記列表
/** Positions and map statuses **/
var isLoaded = false;
/** **/
var refreshIntervalId;
var vehicles;
var map;
function setVehicleAsCenter (registration) {
alert("Hola");
}
function loadPoints (positions) {
console.debug('loading markers');
var lttd;
var lgtd;
for (var i=0; i < positions.length; i++) {
lttd = positions[i].latitude;
lgtd = positions[i].longitude;
marker = map.addMarker({
lat: lttd,
lng: lgtd,
});
markers[positions[i].registration] = marker;
};
map.fitZoom();
isLoaded = true
}
function updatePoints (positions) {
/**
how could be the alorithm here
*/
console.debug('updating markers');
}
function requestPoints() {
$.ajax({
url:'{% url 'gpstracking.ajax.request_tracks' %}',
type: 'get',
dataType: 'json',
data: {
vehicles: vehicles
},
success: function (positions) {
if (isLoaded == false) {
loadPoints (positions);
} else {
updatePoints (positions);
}
}
});
}
$(document).ready(function() {
/** Buttons Click Event Set **/
$('.map-mode').click(function(){
vehicles = '';
$("#jstree").jstree("get_checked",null,true).find('a[rel="vehicle"]').each(function(){
vehicles = vehicles + $.trim(this.text) + "|";
});
if (vehicles == '') {
console.debug('No vehicles to display');
return;
}
option = $(this).attr('rel');
if (option == 'show') {
console.debug('Ordering to show');
clearInterval(refreshIntervalId);
requestPoints();
}
if (option == 'listen') {
console.debug('Listening');
requestPoints();
refreshIntervalId = setInterval("requestPoints()", 10000);
}
if (option == 'clear') {
console.debug('Clearing');
clearInterval(refreshIntervalId);
markers = new Object();
map.removeMarkers();
isLoaded = false;
}
});
/** Map loading **/
map = new GMaps({
div: '#map-canvas',
lat: -16.4237766667,
lng: -71.54262,
});
});