I'm trying to serve requests to Google API using a JavaFX app. I'm using the Google roads API. Problem is I'm asking user to import an excel document with coordinates and the document can hold as many latitude and longitude data as possible but the Google API only allows less than 100 pairs of coordinates. So how can I serve the data which is in an array list from index at position 0 to 99 and on button press serve the next set of coordinates from 100 to 199 or less. I'm currently able to serve the arraylist.sublist(0to99) and get back a json response. Thanks in advance
1 Answer
//On fx button click the following happens
@FXML public void loadURL(Event event){
co_ordinates = Excel_Exchange.value;
if(!next){
limit = (int)co_ordinates.size();
next = true;//some global boolean variable so that this is done once
}
if(co_ordinates.size()<100){
StringBuilder urlCaseOne = new StringBuilder(co_ordinates.subList(start, co_ordinates.size()).toString().replaceAll("[\\[\\]]","").replaceAll(", ",""));
url_link = "https://roads.googleapis.com/v1/snapToRoads?path="+urlCaseOne.deleteCharAt(urlCaseOne.length()-1)+"&interpolate=true&key="+API_KEY;
}else{
if(limit>100){
StringBuilder urlCaseTwo = new StringBuilder(co_ordinates.subList(start, end).toString().replaceAll("[\\[\\]]","").replaceAll(", ",""));
url_link = "https://roads.googleapis.com/v1/snapToRoads?path="+urlCaseTwo.deleteCharAt(urlCaseTwo.length()-1)+"&interpolate=true&key="+API_KEY;
//System.out.println("l"+limit+" s"+start+" e"+end);
start+=100; end+=100; limit-=100;
}else if(limit<100){
StringBuilder urlCaseThree = new StringBuilder(co_ordinates.subList(start, co_ordinates.size()).toString().replaceAll("[\\[\\]]","").replaceAll(", ",""));
url_link = "https://roads.googleapis.com/v1/snapToRoads?path="+urlCaseThree.deleteCharAt(urlCaseThree.length()-1)+"&interpolate=true&key="+API_KEY;
}
}
//System.out.println(co_ordinates.size());
//System.out.println(url_link);
//System.out.println(co_ordinates.toString().lastIndexOf("|"));
//System.out.println(co_ordinates.subList(0, 99).size());
startLoadState.apply();
this.engine.load(url_link);
}// i have another method that navigates back by to the first url
arraylist.sublist(0,99)make the api request and save the date, and thenarraylist.sublist(100,199)make another api request..size()method such thatarraylist.sublist(100, arraylist.size()).