我正在尝试使用 ESRI ArcGIS javascript API 实现实时跟踪功能。我无法根据从数据库中检索到的 lat、lng 移动标记。为了给出一个清晰的概念,这是我们为此目的使用 Google 地图的现有代码。如何使用 ESRI arcGIS javascript API 实现相同的功能?
<script type="text/javascript">
var marker, map, ct=0, geocoder ;
function initialize() {
var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?>);
var mapOptions = {
zoom: 14,
maxZoom: 16,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('main-map'), mapOptions);
geocoder = new google.maps.Geocoder();
var image = new google.maps.MarkerImage(
'assets/images/marker-images/image.png',
new google.maps.Size(20,21),
new google.maps.Point(0,0),
new google.maps.Point(10,21)
);
marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon: image,
title: 'I might be here'
});
}
///////////////////////////////////////////////////
$(function() {
initialize();
live();
setInterval( live , 10000);
});
function live() {
var duration = 10000;
$.ajax({
type: "GET",
url: "otravels_ajax/getlivedata.php?vid=<?php echo $imei; ?>",
dataType: 'xml',
async:false,
success: function(xml) {
$(xml).find("marker").each(function(){
var id = $(this).find('id').text(); lid=id; //alert(lid);
var lat = $(this).find('lat').text();
var lng = $(this).find('lng').text();
var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));//console.log(point);
var ts = $(this).find('ts').text();//alert(ts);
var speed = $(this).find('speed').text();
var status = $(this).find('status').text();
if(status=='A') status="<span class='label label-success '>Active</span>"; else status="<span class='label label-important '>InActive</span>";
var loc_addr = $(this).find('loc').text();
var img=$(this).find('img').text();
var image = new google.maps.MarkerImage(
img,
new google.maps.Size(46,42),
new google.maps.Point(0,0),
new google.maps.Point(23,42)
);
marker.setIcon(image);
marker.animateTo(point, {easing: 'linear', duration: duration});
if(!map.getBounds().contains(point))
map.panTo(point);
// $('#live_data').html("<tr><td>"+ts+"</td><td>"+speed+"KM/HR</td><td>"+status+"</td><td id=\"loc\">"+loc_addr+"</td></tr>");
$("#d_time").html(ts);
$("#d_speed").html(speed+"KM/HR");
$("#d_status").html(status);
geocoder.geocode({
"latLng":point
}, function (results, status) { // alert("fgb");
if (status == google.maps.GeocoderStatus.OK) {
var placeName = results[1].formatted_address; //alert(placeName);
$("#loc").html(placeName);
}
});
});
}
});
}
</script>