AnsweredAssumed Answered

How to use a Closest Facilities on Android v.100.1.0

Question asked by vgallegov on Jul 14, 2017
Latest reply on Aug 15, 2017 by ANohe-esristaff

I am testing the sample code of ClosestFacilityTask| arcgis-android and I can not make it work. I'd appreciate your help. For example:

 

// create ClosestFacilityTask instances
 mClosestFacilityTask
= new ClosestFacilityTask(context, "http://www.yourserver.com/arcgis/rest/services/NetworkAnalysis/CA/NAServer/Closest%20Facility");
 
.....

 
// get default parameters
 
final ListenableFuture paramsFuture = sClosestFacilityTask.createDefaultParametersAsync(); (I guess it's a syntax error)
 paramsFeature
.addDoneListener(new Runnable() {
   
@Override
   
public void run() {
     
try {
       mClosestFacilityParameters
= paramsFuture.get(); (Return Object [] when mClosestFacilityParameters is a ListenableFuture?)

       
// add your Facility
       
List facilities = mClosestFacilityParameters.getFacilities(); (Cannot resolve method)
       facilities
.add(new Facility(new Point(-13045663.744, 4039204.580, WEB_MERCATOR)));

       
// add your Incident
       
List incidents = mClosestFacilityParameters.getIncidents(); (Cannot resolve method)
       incidents
.add(new Incident(new Point(-13052490.008, 4035542.739, WEB_MERCATOR)));

       
// solve
       
final ListenableFuture resultFuture = mClosestFacilityTask.solveClosestFacilityAsync(mClosestFacilityParameters);
       resultFuture
.addDoneListener(new Runnable() {
         
@Override
         
public void run() {
           
try {
             
// get ClosestFacilityRoute by facility and incident indexes
             
ClosestFacilityResult result = resultFuture.get(); (Gives an error because it requires a ClosestFacilityResult and get () returns an Object)
             mClosestFacilityRoute
= result.getRoute(0, 0);
           
} catch (Throwable e) {
             
Log.e(e);
           
}
         
}
       
});
     
} catch (Throwable e) {
       
Log.e(e);
     
}
   
}
 
});

Thanks!!

Outcomes