【发布时间】:2020-04-22 12:39:29
【问题描述】:
大家好,我有这个 ArrayList
public static List<JSONObject> markerList = new ArrayList<JSONObject>();
我用 for (loop) 在里面放了一个 JSONObject 使用来自服务器的 ID 和一些信息 还有一个标记 ID(谷歌地图..)
如何检查数组中的这个对象是否有特定的 id,所以我不再插入它 因为该对象将具有不同的值,例如纬度和经度以及标记 id,但与 ArrayList 中的所有重复对象具有相同的驱动程序 id,这真的让我在想如何检查它我试图在任何地方搜索任何帮助家伙
public static List<JSONObject> markerList = new ArrayList<JSONObject>();
public static void CreateMarker(JSONArray arrayList){
try {
Marker marker;
for (int counter = 0; counter < arrayList.length(); counter++) {
JSONObject json=arrayList.getJSONObject(counter);
int id = json.getInt("id");
int is_active = json.getInt("is_active");
double latitude = json.getDouble("latitude");
double longitude = json.getDouble("longitude");
MarkerOptions markerOptions = new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(String.valueOf(id))
.flat(true)
.anchor(0.5f, 1.0f)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.car_marker_dark));
marker = mGoogleMap.addMarker(markerOptions);
Log.e("MarkerList", "Marker id '" + marker.getId() + "' added to list.");
Log.e("MarkerList", String.valueOf(markerList));
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("is_active",is_active);
jsonObject.put("latitude",latitude);
jsonObject.put("longitude",longitude);
jsonObject.put("Marker",marker);
markerList.add(jsonObject);
}
}catch (Exception e){
e.printStackTrace();
}
}
【问题讨论】:
-
使用
==而不是.equals()。==检查两个对象是否为同一个对象,不检查它们是否具有相同的内容。
标签: java google-maps android-studio arraylist