jna3856

update point location (geometry) in code

Discussion created by jna3856 on Feb 13, 2012
Latest reply on Feb 16, 2012 by jna3856
i would like to enable an "easy button" which will enable field users the ability to move an existing point feature to their device gps location.

essentially, there is a button, "update location" which will update the selected feature's location/geometry and set it's x,y to the user's device x,y.

code is as follows... (however, this does not actually update the selected features geometry, any suggestions?)

var moveButton = new dijit.form.Button({
label : "Update Location",
"class" : "saveButton"
});

dojo.place(moveButton.domNode, attInspector.deleteBtn.domNode, "after");

dojo.connect(moveButton, "onClick", function() {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
myGPS = esri.geometry.geographicToWebMercator(new esri.geometry.Point(position.coords.longitude, position.coords.latitude));
var newGraphic = new esri.Graphic(myGPS, null, null);
updateFeature.geometry = newGraphic.geometry; <<---- the money code line here
}, function(error) {
HideProgressIndicator();
switch (error.code) {
case error.TIMEOUT:
alert('Timeout');
break;
case error.POSITION_UNAVAILABLE:
alert('Position unavailable');
break;
case error.PERMISSION_DENIED:
alert('Permission denied');
break;
case error.UNKNOWN_ERROR:
alert('Unknown error');
break;
}
});
} else {
alert('Browser does not support GeoLocation');
}
updateFeature.getLayer().applyEdits(null, [updateFeature], null);
HideServiceRequestContainer();
reloadLayers(); //to remove/reload layers to overcome the iPad graphics cache issue
});

Outcomes