Android Reverse GeoCoder not working -


hi trying lower battery consumption of application removing location updates in onstop:

@override public void onstop() {      if (mgoogleapiclient.isconnected()) {         //stopping location updates causes error in geocoder can't address??         stoplocationupdates();         mgoogleapiclient.disconnect();     }     super.onstop(); }  protected void stoplocationupdates() {     locationservices.fusedlocationapi.removelocationupdates(             mgoogleapiclient, this); } 

however when geocoder stops working , throws , ioexception, though start location updates again in onconnected:

@override public void onresume() {     super.onresume();     //super class method close nav drawer     updateandclosedrawer(positions.map.position);     if (savedvalues != null) {         if (savedvalues.getstring("email", null) == null) {              onbuttonpressed();         }     }      servicesconnected();     checkgpsenabled();     if (!mgoogleapiclient.isconnected()) {         //log.e("map", "mgoogleapiclient not connected going connect");         mgoogleapiclient.connect();     } }  protected  void startlocationupdates(){     locationservices.fusedlocationapi.requestlocationupdates(mgoogleapiclient, locationrequest, this);  }  @override public void onconnected(bundle bundle) {      startlocationupdates();      //initialize mmap object     setupmapifneeded(); } 

here's error thrown:

        try {             /*              * return 10 addresses.              */                 addresses = geocoder.getfromlocation(loc.getlatitude(),                         loc.getlongitude(), 10);              } catch (ioexception e1) {                 log.e("mapactivity",                         "io exception in getfromlocation()");                 e1.printstacktrace();                 log.e("markerloader", "io exception trying address");             }  

i'm guessing service takes awhile going again after it's stopped, , that's why approach failing. can me understand this?


edit ok after bit of reading seems problem not removing location updates, it's problem geocoder timing out waiting response server. seems best solution write own call server, , wait longer... i'll post solution below.

thanks

do call

mgoogleapiclient.connect(); 

before call

protected  void startlocationupdates(){ locationservices.fusedlocationapi.requestlocationupdates(mgoogleapiclient, locationrequest, this); } 

?


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -