[英]when I add a set of markers from array list it show only the last value from array list?
使用数组列表值在Google地图中添加标记,但是它只能从数组列表中获取Last值,请帮忙。以下是我的循环。
for(int k=0;k<jsonarray2.length();k++)
{
jsonobject2 =jsonarray2.getJSONObject(k);
HashMap<String, String> map1 = new HashMap<String, String>();
map1.put("Lat",jsonobject2.getString("Lat"));
Log.d("Hbbbbbbbbbbbbbbb", "" + jsonobject2.getString("Lat"));
map1.put("Long",jsonobject2.getString("Long"));
map1.put("StopName", jsonobject2.getString("StopName"));
Log.d("Hbbbbbbbbbbbbbbb", "" + jsonobject2.getString("Long"));
// map1.put("LiveLongitude",jsonobject1.getString("LiveLongitude"));
// Log.d("Hbbbbbbbbbbbbbbb", "" + jsonobject1.getString("LiveLongitude"));
arraylist12.add(map1);
Log.e("arraylist12", ""+arraylist12);
for (int m = 0; m < arraylist12.size(); m++) {
final LatLng position = new LatLng(Double .parseDouble(arraylist12.get(m).get("Lat")),Double.parseDouble(arraylist12.get(m).get("Long")));
Log.e("position", ""+position);
String stopname = arraylist12.get(m).get("StopName");
if(mark!=null){
mark.remove();
}
final MarkerOptions options = new MarkerOptions().position(position);
//mMap.addMarker(options);
mark=mMap.addMarker(new MarkerOptions().position(position).icon(BitmapDescriptorFactory .fromResource(R.drawable.bustour)).title(stopname));
}
我认为使用这么多代码可以通过循环添加多个标记。
for (int m = 0; m < arraylist12.size(); m++) {
final LatLng position = new LatLng(Double .parseDouble(arraylist12.get(m).get("Lat")),Double.parseDouble(arraylist12.get(m).get("Long")));
String stopname = arraylist12.get(m).get("StopName");
mark=mMap.addMarker(new MarkerOptions().position(position).icon(BitmapDescriptorFactory .fromResource(R.drawable.bustour)).title(stopname));
}
如果您将使用if(mark!=null){mark.remove();}
,那么它将在添加新标记之前删除最后一个标记。因此最后您只能看到最后一个标记。
编辑
您要在添加新标记集之前删除标记集,然后在添加新标记集之前清除地图。
类似于: mMap.clear();
然后添加新集合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.