0

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.

marciokoko
  • 4,988
  • 8
  • 51
  • 91
  • There can be two type of distances between two location, straight line distance and path. Which one you want ? – Piyush Agarwal Jan 31 '14 at 20:09
  • Then possible duplicate of http://stackoverflow.com/questions/10683554/distance-calculation-from-my-location-to-destination-location-in-android – Piyush Agarwal Feb 01 '14 at 03:49

0 Answers0