android - Geocoder goes good in an Activity and in another returns null always -


i working in app maps, in first activity have navigationdrawer differents fragments, in 1 of them last location every 10 seconds , set textview address of location. going perfect since create new activity details of place mapview , when put marker address, return null don´t know why..

there code. 1rst activity fragment

public void setlocationlisteners() {     if (activitycompat.checkselfpermission(getactivity(), manifest.permission.access_fine_location) != packagemanager.permission_granted) {          activitycompat.requestpermissions(getactivity(),                 new string[]{manifest.permission.access_fine_location},                 request_permission_location);     } else {         mlocationcallback = new locationcallback() {             @override             public void onlocationresult(locationresult locationresult) {                 location lastlocation = locationresult.getlastlocation();                 address address = getaddress(lastlocation.getlongitude(), lastlocation.getlatitude(), getcontext());                 mylocation = new latlng(lastlocation.getlatitude(), lastlocation.getlongitude());                 if (address == null) {                     ((textview) mview.findviewbyid(r.id.txtvosestas)).settext(string.valueof(                             lastlocation.getlongitude() + " " + lastlocation.getlatitude()));                 } else                     ((textview) mview.findviewbyid(r.id.txtvosestas)).settext(address.getaddressline(0).split(",")[0]);                  ((textview) mview.findviewbyid(r.id.txtbearing)).settext(string.valueof(lastlocation.getbearing()));                 ((textview) mview.findviewbyid(r.id.txtvelocidad)).settext(string.valueof(lastlocation.getspeed()));             }         };     }  } 

"getaddress" static method in maphelper

public static address getaddress(double lng, double lat, context c) {     geocoder geocoder = new geocoder(c, locale.getdefault());     try {         list<address> addresses = geocoder.getfromlocation(lat, lng, 1);         return addresses.get(0);     } catch (ioexception e) {         e.printstacktrace();     } catch (indexoutofboundsexception e) {     }     return null; } 

i call same method in other activity when map ready.

@override public void onmapready(googlemap googlemap) {     mmap = googlemap;     mmap.setonmaplongclicklistener(new googlemap.onmaplongclicklistener() {         @override         public void onmaplongclick(latlng latlng) {             mmap.clear();             mmap.addmarker(new markeroptions().position(latlng));             string lat = string.format("%.7f", latlng.latitude);             string lng = string.format("%.7f", latlng.longitude);             ((textview) findviewbyid(r.id.txtlat)).settext(lat);             ((textview) findviewbyid(r.id.txtlng)).settext(lng);             address address = getaddress(double.valueof(lat), double.valueof(lng), getapplicationcontext());             ((multiautocompletetextview) findviewbyid(r.id.txtdireccion)).settext(address != null? address.getaddressline(0) : "sin dirección");         }     });     if (mlugar != null){         mmap.movecamera(cameraupdatefactory.newlatlngzoom(mlugar.getlatlng(), 15));         markeroptions marker = new markeroptions()                 .position(mlugar.getlatlng())                 .title(mlugar.getnombre());         mmap.addmarker(marker);     } } 

and in never results.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -