arrays - How to parse json into android to compare users location to nearest 10 locations? -
im getting server response store locations , master array 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 loop through each store, lat/long, compare users location, create new array top 5 nearest locations.
ive got far:
try { //get master array of locations jsonarray jsonarray = new jsonarray(arrays.aslist(contentasstring));
//loop through each dictionary in array (int = 0; < jsonarray.length; i++) { //get lat&long jsonobject sys = jsonarray.getjsonobject("master"); name = sys.getstring("name"); latitude = sys.getstring("lat"); longitude = sys.getstring("long"); //create location object //send location.distanceto() method //create new array distance field added original values } //sort , nearest 5 locations //create cards top 5 locations //better use mirror api } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); }
what im stuck in creating location object , how hook distanceto method empty:
//get distances public float distanceto (location dest) { //compare distance passed user location //return distance float return 1; }
any appreciated.
Comments
Post a Comment