【发布时间】:2015-02-14 09:40:24
【问题描述】:
我正在开发一个应用程序,当应用程序第一次启动时,它会从我的服务器获取所有纬度和经度位置,并根据标记在地图上显示它们。之后,我的应用程序开始通过推送机制接收坐标,我为此实现了 Google Cloud Messaging GCM。所以现在我想要我的应用程序通过 GCM 接收到的坐标,它首先检查地图上是否已经存在具有相同纬度和经度的标记,如果是,然后从地图中删除该标记。请指导我如何实现这一目标。
这是我的应用程序第一次启动并通过服务从服务器获取坐标时的代码。
user = json.getJSONArray(TAG_GPS);
String Latitude, Longitude, Type;
LatLng latLngGps;
int a=user.length();
for(int i=0;i<a;i++){
JSONObject c=user.getJSONObject(i);
Latitude=c.getString(TAG_LAT);
Longitude=c.getString(TAG_LONG);
ID=c.getString(TAG_ID);
mGoogleMap .addMarker(new MarkerOptions().position(latLngGps).title("A").icon(BitmapDescriptorFactory.fromResource(R.drawable.red)));
}
这就是我通过 GCM 获取坐标的方式
json = new JSONObject(message);
String lat = json.getString("lati");
String lon = json.getString("longi");
Double l1,l2;
l1 = Double.parseDouble(lat);
l2 = Double.parseDouble(lon);
LatLng newLatLong = new LatLng(l1, l2);
//Here i want to check where marker with same position already present on map or not if yes delete that maker otherwise plot a marker on map
LatLng newLatLong = new LatLng(l1, l2);
map.addMarker(new MarkerOptions().position(newLatLong)
.title("GCM"));
【问题讨论】:
标签: android google-maps google-maps-markers google-maps-android-api-2 google-cloud-messaging