I want to do a check of GPS location against geofence polygons at intervals, perhaps once a minute. Based upon some example code I found, I've attemped to use GeometryEngine's within operation to compare the point geometry with the polygon geometry.
Using the markup/JS below, when I execute:
zoneBoundaries.queryFeatures(queryParameters);
I always get withinZone as false, even with one huge polygon geometry to test against. I'm having difficulty figuring out how to troubleshoot this. Any suggestions? I really like the GeometryEngine approach to this, and would like to get this working! Thanks for any tips/assistance. --Ray
//Feature service for spatial query
ServiceFeatureTable {
id: zoneBoundaries
url: "https://services3.arcgis.com/pKp5WOFjeV9KSSfr/ArcGIS/rest/services/fake_brushview_polygons/FeatureServer/0"
onQueryFeaturesStatusChanged: {
if (queryFeaturesStatus === Enums.TaskStatusCompleted) {
//Create array for features
var features = []
// get the features
while (queryFeaturesResult.iterator.hasNext) {
console.log( "Counting.." );
features.push(queryFeaturesResult.iterator.next());
}
console.log( "number of features in array: ", features.length );
//assign geometry of first feature to var:
var zoneGeometry = features[0].geometry
console.log("zoneGeometry", zoneGeometry)
//Get the current map point
//var newPoint = mapView.currentViewpointCenter.center
var newPoint = mapView.locationDisplay.positionSource.position
console.log("newPoint", newPoint)
//Check to see if currrent point is within zone boundary
var withinZone = GeometryEngine.within(newPoint, zoneGeometry)
console.log("withinZone", withinZone)
}
}
}
//Parameters for query
QueryParameters {
id: queryParameters
whereClause: "1=1"
returnGeometry: true
}