google maps - Android - How to show nearby user markers? -


i have android app users can register , when logged in location visible markers on map shown in image. want show nearby marker within 100 meters.

please me exact coding section , object initialization.

enter image description here

here code fetching user markers(lat,lng) database:

private void getnearbymarkers(){      geofireref.addvalueeventlistener(new valueeventlistener() {         @override         public void ondatachange(datasnapshot datasnapshot) {              (datasnapshot locationsnapshot : datasnapshot.getchildren()){                  locationdata locations = locationsnapshot.getvalue(locationdata.class);                  final double templat = double.parsedouble(locations.getlatitude());                 final double templng = double.parsedouble(locations.getlongitude());                 final string uid = locations.getuid();                 databasereference3.addvalueeventlistener(new valueeventlistener() {                     @override                     public void ondatachange(datasnapshot datasnapshot) {                         string name = datasnapshot.child(uid).child("name").getvalue().tostring();                         string business = datasnapshot.child(uid).child("business").getvalue().tostring();                          latlng alllatlang = new latlng(templat,templng);                         markeroptions markeroptions = new markeroptions();                         markeroptions.position(alllatlang);                         markeroptions.title(name);                         markeroptions.snippet(business);                         markeroptions.icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_orange));                          locationmarker = mmap.addmarker(markeroptions);                     }                      @override                     public void oncancelled(databaseerror databaseerror) {                      }                 });              }         }          @override         public void oncancelled(databaseerror databaseerror) {          }     });  } 

thank time , assistance in matter.

you can try sphericalutil.computedistancebetween, need add dependency,

dependencies {     compile 'com.google.maps.android:android-maps-utils:0.5+' } 

and can try in code,

markeroptions.visible(false);// dont need show, if less 100 meter can show, otherwise create , make visble or not later  locationmarker = mmap.addmarker(markeroptions);  latlng yourlatlang = new latlng([your lat],[your lang]); if (sphericalutil.computedistancebetween(yourlatlang, locationmarker.getposition()) < 100) {     locationmarker.setvisible(true); } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -