Hi,
I am using the Track widget simulation for tracking vehicle
Track widget simulation | ArcGIS API for JavaScript 4.11
I would like to input coordinates from database in place of this
var coords = [
{
lat: 34.05648363780692,
lng: -117.19565501782613
},
{
lng: -117.19565880345007,
lat: 34.05682230352545
},
{
lng: -117.19566258907402,
lat: 34.05716096924398
},
},
How can i do the same.
JS API does not have access to server side technology like database access so you have to have a web service that returns JSON results for the database data and then it is simple as using an esriRequest to get the data and then just make sure the data is in an array with objects having lat and lng properties.
Hi,
I tried to react and post lat long through array, but position is jumping irregularly to some location. my code is
function stubGeolocation() {
const layer = new FeatureLayer({
url: "http://xyz/MapServer/0"},
outFields = ["sno","long","lat"]
);
var coords;
layer.queryFeatures().then(function(results){
coords = new Array(totalLength);
for(i=0; i<10; i++)
{
coords="lng: "+(results.features.getAttribute("long"))+","+" lat: "+(results.features.getAttribute("lat"));
}
});
currentCoordIndex = 0;
geolocate.use();
setInterval(function() {
geolocate.change(coords[currentCoordIndex]);
currentCoordIndex = (currentCoordIndex + 1) % coords.length;
}, 2000);
}
});
Your array "coords", is an array of strings When it should be an array of objects with lat and lng properties.
Could you help me with the code.
even i changed the following but result the same
for(i=0; i<10; i++)
{
coords="lng: "+(results.features.getAttribute("long"))+","+" lat: "+(results.features.getAttribute("lat"));
}
to....
for(i=0; i<10; i++)
{
coords=(results.features.getAttribute("long"))+",\n "+(results.features.getAttribute("lat"));
}
Satyanarayana,
Nope, that is not creating a object with properties either.
var coords;
layer.queryFeatures().then(function(results){
coords = new Array(totalLength);
for(i=0; i<10; i++){
coords[i]= {
"lng": results.features[i].getAttribute("long"),
"lat": results.features[i].getAttribute("lat")
};
}
});
But this will not help that much either now that I see your video. You can not jump around the world every second and expect the map to gather and draw all the basemap tiles in that amount of time. If you were moving less distance or giving more time between locations then it will smooth out.