Im getting the server response for store locations and its basically a master array with dictionaries:
[ masterArray : {name = main, lat = 15.948 long= 88.853 }, {name = 5th Street, lat = 15.294 long= 88.743 }, {name = Cannes Blvd, lat = 15.235 long= 88.765 }, ]
I need to loop through each store, get the lat/long, compare it to users location, create a new array with just the top 5 nearest locations.
Ive got this so far:
try { //Get master array of locations JSONArray jsonArray = new JSONArray(Arrays.asList(contentAsString));
//Loop through each dictionary in array
for (int i = 0; i < jsonArray.length; i++) {
//Get the lat&long for
JSONObject sys = jsonArray.getJSONObject("master");
name = sys.getString("name");
latitude = sys.getString("lat");
longitude = sys.getString("long");
//Create location object
//Send to Location.distanceTo() method
//Create new array with distance field added to the original values
}
//Sort and get nearest 5 locations
//Create cards for top 5 locations only
//better use Mirror API
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
What Im stuck in is creating the location object and how to hook that up to the distanceTo method which currently is empty:
//Get distances
public float distanceTo (Location dest) {
//Compare distance passed to user location
//return distance float
return 1;
}
Any help will be much appreciated.