This is a ListView I get to display with the cities and places available. I want to show the distance from the current point to the listed places.
eg:
+++++++++++++++++++++++++
Name :Hotel Hilton
Category :hotel
distance:1km
+++++++++++++++++++++++++
How do I calculate and display each distance value on the list?
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
JSONArray jsonArray = new JSONArray(response);
if (jsonArray != null) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = (JSONObject) jsonArray.get(i);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_Name, object.getString("name"));
map.put(TAG_Category, object.getString("category"));
map.put(TAG_Lat, object.getString("lat"));
map.put(TAG_Lng, object.getString("lng"));
contactList.add(map);
}
}
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.menu_list_row, new String[] { TAG_Name,
TAG_Category }, new int[] { R.id.LR_Name,
R.id.LR_date });
list.setAdapter(adapter);
}
Current position is identified from GPS and stors as lat,lng.
You can use:
given that first two parameters are doubles, representing your object’s position, while
latandlngvariables contain your current position.Result, expressed in meters, will be at
res[0]