Android LocationListner ... Feeling Sucked :( -



Android LocationListner ... Feeling Sucked :( -

does able find working solution guraneteed phone call onlocationchanged(...) method of locationlistener? looks many peoples facing issue. https://code.google.com/p/android/issues/detail?id=57707 implentation not @ getting called after trying , trying many ways...

public class mylocationlistener implements locationlistener{ final string _logtag = "location listener"; public void onlocationchanged(location location) { string provider = location.getprovider(); double lat = location.getlatitude(); double lng = location.getlongitude(); float accuracy = location.getaccuracy(); long time = location.gettime(); log.d("long"," "+lng); string logmessage = loghelper.formatlocationinfo(provider, lat, lng, accuracy, time); log.d(_logtag, "monitor location:" + logmessage); } public void onstatuschanged(string s, int i, bundle bundle) { string statusmessage = loghelper.translatestatus(i); // log.d(_logtag, "monitor location - status:" + statusmessage); set<string> keys = bundle.keyset(); for(string key:keys){ log.d(_logtag, "monitor location - bundle key:" + key); } } public void onproviderenabled(string s) { log.d(_logtag, "monitor location - provider enabled user: " + s); } public void onproviderdisabled(string s) { log.d(_logtag, "monitor location - provider disabled user: " + s); } }

this i've used in past, works pretty me:

public class locationservice extends service implements googleplayservicesclient.connectioncallbacks, googleplayservicesclient.onconnectionfailedlistener, com.google.android.gms.location.locationlistener { private locationreceiver locationreceiver = new locationreceiver(); public locationclient locationclient; public locationrequest locationrequest; private location previous; string tag = "locationservice"; private boolean monitorlocation; private boolean googleservicesavailable = false; @override public void oncreate() { super.oncreate(); this.monitorlocation = false; //this.locationlistener = new locationlistener(); this.locationrequest = locationrequest.create(); this.locationrequest.setpriority(locationrequest.priority_balanced_power_accuracy); // utilize high accuracy this.locationrequest.setinterval(singletons.location.regularintervaltime); // setting update interval 5mins this.locationrequest.setfastestinterval(singletons.location.fastintervaltime); // set fastest update interval 1 min this.googleservicesavailable = servicesconnected(); this.locationclient = new locationclient(this, this, this); } public boolean servicesconnected() { int resultcode = googleplayservicesutil.isgoogleplayservicesavailable(this); if (resultcode == connectionresult.success) { //log.d(tag, "locationservice: location services available"); homecoming true; } else { log.e(tag, "location services not available"); homecoming false; } } @override public int onstartcommand(intent intent, int flags, int startid) { super.onstartcommand(intent, flags, startid); if (!this.googleservicesavailable || this.locationclient.isconnected() || this.monitorlocation) { //log.d(tag, "locationservice: services started"); homecoming start_sticky; } setuplocationclientifneeded(); if (!this.locationclient.isconnected() || !this.locationclient.isconnecting() && !this.monitorlocation) { //log.d(tag, "locationservice: service starting now"); this.monitorlocation = true; this.locationclient.connect(); } homecoming service.start_sticky; } public void setuplocationclientifneeded() { if (this.locationclient == null) { this.locationclient = new locationclient(this, this, this); } } @override public void onlocationchanged(location location) { if (this.previous == null) { this.previous = location; } if (!this.issamelocation(location, this.previous)) { locationdatasource datasource = new locationdatasource(getapplicationcontext()); datasource.open(); datasource.insertnewlocation(location, this.previous); datasource.close(); this.previous = location; } } @override public ibinder onbind(intent intent) { homecoming null; } @override public void onconnected(bundle bundle) { this.locationclient.requestlocationupdates(this.locationrequest, this); } @override public void ondisconnected() { this.monitorlocation = false; this.locationclient = null; } @override public void onconnectionfailed(connectionresult connectionresult) { this.monitorlocation = false; if (connectionresult.hasresolution()) { log.d(tag, "locationservice: can resolve problem?"); // if no resolution available, display error dialog } else { log.e(tag, "locationservice: cannot resolve gms location problem"); } } @override public void ondestroy() { // turn off request flag this.monitorlocation = false; if (this.googleservicesavailable && this.locationclient != null) { //this.locationclient.removelocationupdates(this); // destroy current location client this.locationclient = null; } super.ondestroy(); } public boolean issamelocation(location l, location p) { homecoming (p.getlongitude() == l.getlongitude()) && (p.getlatitude() == l.getlatitude()); } }

android android-location locationlistener

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -