Hi Agnes, You are right, the Distance object should probably return a double instead of an integer. Remember that the callback is asynchronous yet your DirectionsCallback local class needs to access the indexes of the enclosing loops. In order to do that, Java will force the index variables to be final, but then you can't increment them as part of the loop. You could assign the indexes into new final local variables that your callback instances uses, or you can create a new class that receives the indexes that it needs as part of the constructor.
HTH, On Thu, Aug 28, 2008 at 8:45 AM, agnes Laffitte <[EMAIL PROTECTED]>wrote: > I have questions regarding the Maps API that is part of the > http://code.google.com/p/gwt-google-apis/ project using the gwt-map.jar > file. > Sample Code: > package de.herbstcampus.server; > > import java.io.IOException; > import java.io.PrintWriter; > import java.util.ArrayList; > > import com.google.gwt.core.client.GWT; > import com.google.gwt.maps.client.MapWidget; > import com.google.gwt.maps.client.geocode.DirectionQueryOptions; > import com.google.gwt.maps.client.geocode.DirectionResults; > import com.google.gwt.maps.client.geocode.Directions; > import com.google.gwt.maps.client.geocode.DirectionsCallback; > import com.google.gwt.maps.client.geocode.DirectionsPanel; > import com.google.gwt.maps.client.geocode.StatusCodes; > import com.google.gwt.maps.client.geocode.Waypoint; > import com.google.gwt.user.client.Window; > > public class CVRPOutputs > { > > /* Instance fields */ > > private String outFile; > private ArrayList<Node> nodesList; > private ArrayList<Waypoint[]> costsMatrix; > private double[][] Distance; > > /* Class constructor */ > > CVRPOutputs(String outputFileName, ArrayList<Node> setOfNodes, > > ArrayList<Waypoint[]> cMatrix) > { > outFile = outputFileName; > nodesList = setOfNodes; > costsMatrix = cMatrix; > > } > public double[][] costsMatrix( ArrayList<Waypoint[]> cMatrix){ > int index=0; > int indey=(nodesList.size()*nodesList.size()-nodesList.size())/2; > Waypoint[][][] distmat = null; > MapWidget map= null; > DirectionsPanel directionsPanel=null; > DirectionQueryOptions opts = new DirectionQueryOptions(map, > directionsPanel); > > for(int i=0; i<nodesList.size();i++) > {for(int j=1+i; j<nodesList.size();j++) > { > distmat[i][j]=cMatrix.get(index); > index ++; > } > } > for(int i=0; i<nodesList.size();i++) > { > for(int j=1+i;j<nodesList.size();j++) > { > distmat[j][i]=cMatrix.get(indey); > indey++; > } > } > for(final int ii=0; ii<nodesList.size();ii++) > { > for(final int jj=0;jj<nodesList.size();jj++) > { > Directions.loadFromWaypoints(distmat[ii][jj], opts, new > DirectionsCallback() { > > public void onFailure(int statusCode) { > Window.alert("Failed to load directions: Status " > + StatusCodes.getName(statusCode) + " " + > statusCode); > } > > public void onSuccess(DirectionResults result) { > GWT.log("Successfully loaded directions.", null); > Distance[ii][jj]=result.getDistance().inMeters(); > } > > > > }); > > } > } > > for(final int iii=0; iii<nodesList.size();iii++) > { > for(final int jjj=0;jjj<nodesList.size();jjj++) > { > Directions.loadFromWaypoints(distmat[jjj][iii], opts, new > DirectionsCallback() { > > public void onFailure(int statusCode) { > Window.alert("Failed to load directions: Status " > + StatusCodes.getName(statusCode) + " " + > statusCode); > } > > public void onSuccess(DirectionResults result) { > GWT.log("Successfully loaded directions.", null); > Distance[jjj][iii]=result.getDistance().inMeters(); > } > > > > }); > > } > } > return Distance; > } > > > public void printOutputFile() > { > try > { > PrintWriter out = new PrintWriter(System.currentTimeMillis() + > outFile); > > out.println("***************************************************"); > out.println("* > *"); > out.println("* RESULTS FROM SIMUROUTE PROJECT > *"); > out.println("* > *"); > > out.println("***************************************************"); > > out.println("\r\n"); > > out.println("***************************************************"); > out.println("* COSTS MATRIX > *"); > > out.println("***************************************************"); > out.println("\r\nCOSTS MATRIX:\n"); > for (int i = 0; i < nodesList.size(); i++) > for (int j = 0; j <= i; j++) > out.println(i + " " + j + " " + Distance[i][j]); > > out.close(); > } > catch (IOException exception) > { > System.out.println("Error processing output file: " + > exception); > } > > } > } > Eclipse wanted int ii , int iii and int jj, int jjj to be declared final > for some reason, and then i get an error that > The final local variable jj cannot be assigned. It must be blank and not > using a compound assignment. It went back and forward saying to change ii to > final, and then to remove it. > I want to make a distance matrix. By the way why is the inMeters and int, > in real life driving distances shouldn't it be a double. > Best Regards, > Agnes Laffitte > -- Miguel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
