Hi
I'm trying to apply the coordinates of the tracking made by the Geolocation API.
http://tests.christiansailer.ch/omleth_dozent/tripmeter/esri.htm
Unfortunately it doesn't add the records of the Graphic with the function applyEdit in the way I did with Attributes.
Can sb. help?
Thx.
Code is:
| function initFunc(map) { | |
| var startPos; | |
| if( navigator.geolocation ) { | |
| navigator.geolocation.getCurrentPosition(zoomToLocation, locationError); | |
| watchId = navigator.geolocation.watchPosition(showLocation, locationError); | |
| } else { | |
| alert("Browser doesn't support Geolocation. Visit http://caniuse.com to see browser support for the Geolocation API."); | |
| } | |
| } | |
| function locationError(error) { | |
| //error occurred so stop watchPosition | |
| if( navigator.geolocation ) { | |
| navigator.geolocation.clearWatch(watchId); | |
| } | |
| switch (error.code) { | |
| case error.PERMISSION_DENIED: | |
| alert("Location not provided"); | |
| break; | |
| case error.POSITION_UNAVAILABLE: | |
| alert("Current location not available"); | |
| break; | |
| case error.TIMEOUT: | |
| alert("Timeout"); | |
| break; | |
| default: | |
| alert("unknown error"); | |
| break; | |
| } | |
| } | |
| var positionLayerURL = "http://services1.arcgis.com/i9MtZ1vtgD3gTnyL/arcgis/rest/services/OMLETH_Trackers_20150505/FeatureSe..."; | |
| var positionLayer = new FeatureLayer(positionLayerURL, | |
| {mode: FeatureLayer.MODE_ONDEMAND, | |
| outFields: ["*"] | |
| } | |
| ); | |
| function zoomToLocation(location) { | |
| startPos = location; | |
| var pt = new Point(location.coords.longitude, location.coords.latitude); | |
| dojo.byId("startLat").innerHTML = location.coords.latitude; | |
| dojo.byId("startLon").innerHTML = location.coords.longitude; | |
| addGraphic(pt); | |
| map.centerAndZoom(pt, 12); | |
| } | |
| function showLocation(location) { | |
| //zoom to the users location and add a graphic | |
| var pt = new Point([location.coords.longitude, location.coords.latitude],new SpatialReference({ wkid:4326 })); | |
| var graphic = new Graphic(pt); | |
| if ( !graphic ) { | |
| addGraphic(pt); | |
| } else { // move the graphic if it already exists | |
| graphic.setGeometry(pt); | |
| console.log(positionLayer); | |
| console.log(graphic); | |
| console.log(positionLayerURL); | |
| //applyEdits | |
| positionLayer.applyEdits([graphic],null, null, function(){ | |
| console.log("updateXY"); | |
| }, function(){ | |
| alert("An error occured during update."); | |
| }); | |
| } | |
| map.centerAt(pt); |
Christian,
When you create the new graphic, it needs to have a reference to attributes, even if they are blank. For example:
var att = {};
var graphic = new Graphic(pt,null,att);Without a reference to an attribute, it will fail.
Regards,
Tom