java - LocationClient requestUpdates onLocationChanged never called -


i have code use position map app. tested in galaxy s2 device , works fine, when tested in nexus 4 device onlocationchanged callback never gets called. doing wrong?

here activity code:

    public class basemapactivity extends fragmentactivity implements injectable,         googleplayservicesclient.connectioncallbacks,         googleplayservicesclient.onconnectionfailedlistener, locationlistener {      private final static int connection_failure_resolution_request = 9000;      private mapentity component;     private boolean yetstarted = false;      private locationclient mlocationclient;     private locationrequest mlocationrequest;     private location location;      protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          setcontentview(r.layout.map_activity);         mlocationclient = new locationclient(this, this, this);         mlocationrequest = locationrequest.create();          mlocationrequest.setpriority(locationrequest.priority_high_accuracy); // todo         mlocationrequest.setinterval(5000); // todo         mlocationrequest.setfastestinterval(5000); // todo          replacefragment(r.id.map_container, mapfragment);          // agrega el fragment de extras         fragment extrasfragment = component.getextrasfragment();         replacefragment(r.id.map_extras, extrasfragment);     }      @override     protected void onstart() {         super.onstart();              mlocationclient.connect();     }      @override     protected void onstop() {          if (mlocationclient.isconnected()) {             mlocationclient.removelocationupdates(this);             mlocationclient.disconnect();         }          super.onstop();     }      @override     public void onconnected(bundle arg0) {          mlocationclient.requestlocationupdates(mlocationrequest, this);         location = mlocationclient.getlastlocation();          if (location == null) {             return;         }          toast.maketext(this, "onconnected", toast.length_short).show();     }      @override     public void ondisconnected() {         mlocationclient.removelocationupdates(this);         toast.maketext(this, "ondisconnected. please re-connect.",                 toast.length_short).show();     }      @override     public void onlocationchanged(location location) {         component.setcenter(location);         string msg = "updated location: "                 + double.tostring(location.getlatitude()) + ","                 + double.tostring(location.getlongitude());         toast.maketext(this, msg, toast.length_short).show();     }      @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {          switch (requestcode) {          case connection_failure_resolution_request:              switch (resultcode) {             case activity.result_ok:                 break;             }         }     }      @suppresslint("showtoast")     @override     public void onconnectionfailed(connectionresult connectionresult) {          if (connectionresult.hasresolution()) {             try {                 connectionresult.startresolutionforresult(this,                         connection_failure_resolution_request);             } catch (intentsender.sendintentexception e) {                 e.printstacktrace();             }         } else {             toast.maketext(this, "an error ocurred getting current location",                     toast.length_short);         }      }  } 

whats weird working in 1 device not in other.

try set location mock see if locationchange called or not.

here have example using before production.

private location createmocklocation() {     if (mocklocation == null) {         mocklocation = new location("mock");         mocklocation.setlatitude(41.4934133);         mocklocation.setlongitude(-23.8729252);         mocklocation.setaccuracy(1.0f);         mocklocation.settime(new date().gettime());     } else {         mocklocation.setlatitude(mocklocation.getlatitude() + 0.00003);         mocklocation.setlongitude(mocklocation.getlongitude() + 0.00001);         mocklocation.settime(new date().gettime());     }     return mocklocation; }  private void mocklocation() {     locationservices.fusedlocationapi.setmockmode(clientapi, true);     locationservices.fusedlocationapi.setmocklocation(clientapi, createmocklocation());      final scheduledexecutorservice scheduler = executors.newsinglethreadscheduledexecutor();     scheduler.scheduleatfixedrate(new runnable() {         public void run() {             locationservices.fusedlocationapi.setmocklocation(clientapi, createmocklocation());             // log.d("mocklocation",             // "mocklocation: lat:"+mocklocation.getlatitude()+" long:"+mocklocation.getlongitude());         }     }, 0, normal_interval, timeunit.milliseconds); } 

with method update position each normal_interval in ms.

hope helps :).


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -