Closest facility 10.2.9

282
0
08-19-2017 04:57 AM
VinaSingh
New Contributor

I have created an Online Locator Service because WGS didn't have the facilities I wanted in the application. Now I want to use it to find the closest facilities from "my location". I am using Android SDK 10.2.9. Can anyone help me with the code?

AsyncLocalSearch asycst = new AsyncLocalSearch();
String[] searchCriteria = { "Bus Stations" };
asycst.execute(searchCriteria);


private class AsyncLocalSearch extends AsyncTask<String, Void, Boolean> {
    // Determine if the query returned an array of results
    boolean success = false;
    private Exception mException;


    @Override
    protected void onPostExecute(Boolean result) {
        progress.dismiss();
        callout.hide();
        // send toast message based on results of query
        if (!success) {
            // No search results
            Toast toast = Toast.makeText(busStops.this, "No search results",
                    Toast.LENGTH_LONG);
            toast.show();
        } else {
            // Search results
            Toast toast = Toast.makeText(busStops.this,
                    "Please tap on graphic for detailed information",
                    Toast.LENGTH_LONG);
            toast.show();
        }
    }

    @Override
    protected void onPreExecute() {
        // show progress bar while executing task
        progress = ProgressDialog.show(busStops.this, "",
                "Please wait for search results coming back....", true);
    }

    @SuppressWarnings("boxing")
    @Override
    protected Boolean doInBackground(String... params) {
        // handle case of no parameters
        if (params == null || params.length == 0) {
            success = false;
            return success;
        }
        // remove any previous graphics
        graphicsLayer.removeAll();

        List<LocatorGeocodeResult> results = null;
        UserCredentials uc= new UserCredentials();
        uc.setUserAccount(username,Password);
        String url ="htttps://mycreatedfeatureserviceurl";
        Locator locator = Locator.createOnlineLocator(url,uc);
        ClosestFacilityTask cft = new ClosestFacilityTask(url,uc);
        
        cfp.setDefaultTargetFacilityCount(5); // i am fiddling with the functions to be used after this to get nearest bus stations from my location.
        cfp.getFacilities();

        return success;
    }

}

0 Kudos
0 Replies