我得到了商店位置的服务器响应,它基本上是一个带字典的主数组:
[masterArray: {name = main, lat = 15.948 long = 88.853 }, {name = 5th Street, lat = 15.294 长= 88.743 }, {name =戛纳大道, lat = 15.235 长= 88.765 }, ]
我需要遍历每个商店,获取纬度/经度,将其与用户位置进行比较,创建一个仅包含前5个最近位置的新数组。
到目前为止我已经得到了这个:尝试{ //获取主数组位置 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();
}
我陷入困境的是创建位置对象以及如何将其挂钩到当前为空的distanceTo方法:
//Get distances
public float distanceTo (Location dest) {
//Compare distance passed to user location
//return distance float
return 1;
}
任何帮助将不胜感激。