這是一個ListView,我可以顯示可用的城市和地方。我想顯示從當前點到列出的地點的距離。Android谷歌地圖點之間的距離
如:
+++++++++++++++++++++++++
Name :Hotel Hilton
Category :hotel
distance:1km
+++++++++++++++++++++++++
如何計算並顯示在列表中的每個距離值?
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);
}
當前位置從GPS和stors標識爲lat,lng。
如何將值添加到列表適配器? 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); – Loshi 2012-07-17 14:26:16
@Loshi我想你應該將res [0]添加到字符串數組{TAG_Name,TAG_Category,TAG_distance}和int數組(值?),但我不確定。我寧願重新實現適配器,所以你有更多的控制權。看看http://thinkandroid.wordpress.com/2010/01/13/custom-baseadapters/ – Shine 2012-07-17 14:32:39
thnx隊友得到它:) – Loshi 2012-07-17 15:15:39