Pranav MS Pranav MS -4 years ago 55
Android Question

ARCGIS android not able to get extend from the querytask result

I new in the developping of android applications using ArcGIS android runtime API.

I am trying to zoom to an extend and hightlights that extend . But it is not working in my case.

Feature layer url is

which is getting from ArcGIS online portal.
i have added the layer in the map

ArcGISFeatureLayer fl1 = new ArcGISFeatureLayer(

Here i am getting my
from the user input by using the edittext andi am submitting that to an asyn class to fetch data .

I am calling the sync task on button click and passing the user inputed values to the async task.

declaration section

//query task
private Callout mCallout;
private ViewGroup mCalloutContent;
private Graphic mIdentifiedGraphic;
private String mFeatureServiceURL;
private GraphicsLayer mGraphicsLayer;
private ProgressDialog progress;
EditText _EdtTxtTextToZoom;
Button _BtnZoomToExtend;

In my oncreate method i am definig all the things

mGraphicsLayer = new GraphicsLayer();
LayoutInflater inflater = getLayoutInflater();
mCallout = mMapView.getCallout();
// Get the layout for the Callout from
// layout->identify_callout_content.xml
mCalloutContent = (ViewGroup) inflater.inflate(R.layout.identify_callout_content, null);
mIdentifiedGraphic = getFeature(fl1);
_BtnZoomToExtend.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

String tempEdtTxtTextToZoom= "";
try {
tempEdtTxtTextToZoom = _EdtTxtTextToZoom.getText().toString();
new QueryFeatureLayer().execute(tempEdtTxtTextToZoom);
} catch (NumberFormatException e) {
Toast.makeText(MainActivity.this, "tempEdtTxtTextToZoom.."+tempEdtTxtTextToZoom, Toast.LENGTH_SHORT).show();


private class QueryFeatureLayer extends AsyncTask<String, Void, FeatureResult> {

// default constructor
public QueryFeatureLayer() {

protected void onPreExecute() {
progress =, "", "Please wait....query task is executing");

protected FeatureResult doInBackground(String... params) {
String whereClause = "ward_name ='" + params[0] + "'";
// Define a new query and set parameters
QueryParameters mParams = new QueryParameters();

// Define the new instance of QueryTask
QueryTask queryTask = new QueryTask(mFeatureServiceURL);
FeatureResult results;

try {
// run the querytask
results = queryTask.execute(mParams);
Log.e("results---", String.valueOf(results));
return results;
} catch (Exception e) {
return null;

protected void onPostExecute(FeatureResult results) {

// Remove the result from previously run query task

// Define a new marker symbol for the result graphics
SimpleMarkerSymbol mGreenMarkerSymbol = new SimpleMarkerSymbol(Color.GREEN, 15, SimpleMarkerSymbol.STYLE.CIRCLE);

// Envelope to focus on the map extent on the results
Envelope extent = new Envelope();

// iterate through results
for (Object element : results) {
// if object is feature cast to feature
if (element instanceof Feature) {
Feature feature = (Feature) element;
// convert feature to graphic
Graphic graphic = new Graphic(feature.getGeometry(), mGreenMarkerSymbol, feature.getAttributes());
// merge extent with point
Log.e("points----", String.valueOf(graphic.getGeometry()));
// add it to the layer
Log.e("points----", String.valueOf(extent));
// Set the map extent to the envelope containing the result graphics
mMapView.setExtent(extent, 100);
// Disable the progress dialog


Can you please figure it out where i am doing the mistake ?

Answer Source

In the above example im trying to zoom points but actually i wanted the polygon Below is the correct code to zoom a particular polygons extent

            for (Object element : results) {
                progress.incrementProgressBy(size / 100);
                if (element instanceof Feature) {
                    Feature feature = (Feature) element;

                    // turn feature into graphic
                    Graphic graphic = new Graphic(feature.getGeometry(),
                            feature.getSymbol(), feature.getAttributes());
                    Polygon p = (Polygon) graphic.getGeometry();

                    // add graphic to layer
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download