How to check marker with same geo coordinates already exists in Google maps v2? Android -


i developing app in first time when app starts fetch locations in terms of latitude , longitude server , show them on map in terms of markers. after app starts receiving coordinates through pushing mechanism implement google cloud messaging gcm. want coordinate app receive through gcm first check whether marker same latitude , longitude present on map or not if yes remove marker map. please guide me how can achieve this.

here code when first time app start , fetch coordinates server through service.

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))); } 

and how getting coordinate through 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 want check marker same position present on map or not if yes delete maker otherwise plot marker on map     latlng newlatlong = new latlng(l1, l2);                 map.addmarker(new markeroptions().position(newlatlong)                               .title("gcm")); 

you can build set<latlng> , store initial marker locations there. then, when receive new locations via gcm, check if set contains newlatlong. if so, can delete it, otherwise create marker map , add newlatlong set.

however, , depending on data sources, might end latlngs "almost" equal not quite. if that's issue, instead of checking if set "contains" new latlng, may want more sophisticated checks whether new latlng "almost equal" of latlngs in set.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -