how to show multiple users current location on google map in android -


i developing app using google map, want show multiple users location 1 admin on google map. following code show user current location.now please suggest me how can show multiple users location on google map?

//java activity public class locationactivity extends fragmentactivity implements         com.google.android.gms.location.locationlistener,         googleapiclient.connectioncallbacks,         googleapiclient.onconnectionfailedlistener {      private static final string tag = "locationactivity";     private static final long interval = 1000 * 60 * 1; //1 minute     private static final long fastest_interval = 1000 * 60 * 1; // 1 minute      private static final float smallest_displacement = 0.25f; //quarter of meter     button btnfusedlocation;     textview tvlocation;     locationrequest mlocationrequest;     googleapiclient mgoogleapiclient;     location mcurrentlocation;     string mlastupdatetime;     googlemap googlemap;      private double longitude;     private double latitude;     private arraylist<latlng> points; //added     polyline line; //added      protected void createlocationrequest() {         mlocationrequest = new locationrequest();         mlocationrequest.setinterval(interval);         mlocationrequest.setfastestinterval(fastest_interval);         mlocationrequest.setsmallestdisplacement(smallest_displacement); //added         mlocationrequest.setpriority(locationrequest.priority_high_accuracy);     }     /*     protected void createlocationrequest() {         mlocationrequest = new locationrequest();         mlocationrequest.setinterval(interval);         mlocationrequest.setfastestinterval(fastest_interval);         mlocationrequest.setpriority(locationrequest.priority_high_accuracy);     }  */      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         log.d(tag, "oncreate ...............................");          points = new arraylist<latlng>();         //show error dialog if goolgleplayservices not available         if (!isgoogleplayservicesavailable()) {             finish();         }         createlocationrequest();         mgoogleapiclient = new googleapiclient.builder(this)                 .addapi(locationservices.api)                 .addconnectioncallbacks(this)                 .addonconnectionfailedlistener(this)                 .build();          setcontentview(r.layout.activity_location_google_map);         supportmapfragment fm = (supportmapfragment) getsupportfragmentmanager()                 .findfragmentbyid(r.id.map);         googlemap = fm.getmap();         googlemap.getuisettings().setzoomcontrolsenabled(true);          if (getintent().getextras() != null) {             final bundle bundle = getintent().getbundleextra("location");             latitude = bundle.getdouble("latitude");             longitude = bundle.getdouble("longitude");         }     }      @override     public void onstart() {         super.onstart();         log.d(tag, "onstart fired ..............");         mgoogleapiclient.connect();     }      @override     public void onstop() {         super.onstop();         log.d(tag, "onstop fired ..............");         mgoogleapiclient.disconnect();         log.d(tag, "isconnected ...............: " + mgoogleapiclient.isconnected());     }      private boolean isgoogleplayservicesavailable() {         int status = googleplayservicesutil.isgoogleplayservicesavailable(this);         if (connectionresult.success == status) {             return true;         } else {             googleplayservicesutil.geterrordialog(status, this, 0).show();             return false;         }     }      @override     public void onconnected(bundle bundle) {         log.d(tag, "onconnected - isconnected ...............: " + mgoogleapiclient.isconnected());         startlocationupdates();     }      protected void startlocationupdates() {         pendingresult<status> pendingresult = locationservices.fusedlocationapi.requestlocationupdates(                 mgoogleapiclient, mlocationrequest, this);         log.d(tag, "location update started ..............: ");     }      @override     public void onconnectionsuspended(int i) {      }      @override     public void onconnectionfailed(connectionresult connectionresult) {         log.d(tag, "connection failed: " + connectionresult.tostring());     }      @override     public void onlocationchanged(location location) {         log.d(tag, "firing onlocationchanged..............................................");         mcurrentlocation = location;         mlastupdatetime = dateformat.gettimeinstance().format(new date());         addmarker();          longitude = location.getlongitude();         latitude = location.getlatitude();         latlng latlng = new latlng(latitude, longitude); //you have         points.add(latlng); //added         redrawline();     }      private void addmarker() {         markeroptions options = new markeroptions();          // following 4 lines requires 'google maps android api utility library'         // https://developers.google.com/maps/documentation/android/utility/         // have used display time title location markers         // can safely comment following 4 lines info         icongenerator iconfactory = new icongenerator(this);         iconfactory.setstyle(icongenerator.style_purple);         options.icon(bitmapdescriptorfactory.frombitmap(iconfactory.makeicon(mlastupdatetime)));         options.anchor(iconfactory.getanchoru(), iconfactory.getanchorv());          latlng currentlatlng = new latlng(mcurrentlocation.getlatitude(), mcurrentlocation.getlongitude());         options.position(currentlatlng);         marker mapmarker = googlemap.addmarker(options);         long attime = mcurrentlocation.gettime();         mlastupdatetime = dateformat.gettimeinstance().format(new date(attime));         mapmarker.settitle(mlastupdatetime);         log.d(tag, "marker added.............................");         googlemap.movecamera(cameraupdatefactory.newlatlngzoom(currentlatlng,                 13));         log.d(tag, "zoom done.............................");     }      @override     protected void onpause() {         super.onpause();         stoplocationupdates();     }      protected void stoplocationupdates() {         locationservices.fusedlocationapi.removelocationupdates(                 mgoogleapiclient, this);         log.d(tag, "location update stopped .......................");     }      @override     public void onresume() {         super.onresume();         if (mgoogleapiclient.isconnected()) {             startlocationupdates();             log.d(tag, "location update resumed .....................");         }     }     // map line    private void redrawline(){         googlemap.clear();  //clears markers , polylines        polylineoptions options = new polylineoptions().width(5).color(color.blue).geodesic(true);        (int = 0; < points.size(); i++) {            latlng point = points.get(i);            options.add(point);        }        addmarker(); //add marker in current position        line = googlemap.addpolyline(options); //add polyline     } } 

you can add multiple markers corresponding locations of different users.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -