I am having some troubles with the while loop + query. What I'm trying to do is track the user location (using onlocationChanged) and keep querying a FeatureLayer until the query returns a result and then stop the while loop is using a boolean.
The problem once the "while" loop is launched is that the application freezes, here's my code:
boolean noResults=true
while(noResults)
{
pointGeometry=MyPosition;
//myPosition is changing it's value in "onLocationChanged" using the listener, see code below
Graphic pointGraphic = new Graphic(pointGeometry, simpleMarker);
SpatialReference spatialRef = MapFragment.mMapView.getSpatialReference();
Unit unit = spatialRef.getUnit();
double adjustedAccuracy = b_dist;
Polygon p = GeometryEngine.buffer(pointGeometry, spatialRef,adjustedAccuracy, unit);
Query q = new Query();
q.setGeometry(p);
q.setSpatialRelationship(SpatialRelationship.INTERSECTS);
fLayer.selectFeatures(q, SELECTION_METHOD.NEW, callback4);
}
public void onLocationChanged(Location loc) {
double locy = loc.getLatitude();
double locx = loc.getLongitude();
Point wgspoint = new Point(locx, locy);
mLocation = (Point) GeometryEngine.project(wgspoint,
SpatialReference.create(4326),
mMapView.getSpatialReference());
//Here's where myPosition changes its value.
myPosition = mLocation;
}
CallbackListener<FeatureSet> callback4 = new CallbackListener<FeatureSet>() {
public void onCallback(FeatureSet fSet) {
Graphic[] grh=fSet.getGraphics();
if(grh.length>0){
noResults=false;
showTaost("there's a result");
}
});
Is there an alternative to the while loop to fix this? If not, how can I use something like a delay (query the Feature Layer every 5 secondes or something like that)?