android - addressList size is 0 Google Maps -


i 'm trying use google maps. have code:

        public void onmapready(googlemap googlemap) {          mmap = googlemap;         mmap.getuisettings().setzoomcontrolsenabled(true);           list <address> addresslist = null;         if (location != null || !location.equals("")){             geocoder geocoder = new geocoder(this);             try {                 addresslist = geocoder.getfromlocationname(location, 1);               }catch (ioexception e){                 e.printstacktrace();             }             address address = addresslist.get(0);             latlng latlng = new latlng(address.getlatitude(), address.getlongitude());             mmap.addmarker(new markeroptions().position(latlng).title(location));             mmap.movecamera(cameraupdatefactory.newlatlngzoom(latlng, 15));         }     } 

but receive this: addresslist size 0. error "java.lang.indexoutofboundsexception: invalid index 0, size 0" location variable works fine. doing wrong? lot.

possibilities of getting 0 result

list getfromlocationname (string locationname, int maxresults) : returns : list of address objects. returns null or empty list if no matches found or there no backend service available.

and before calling method of geocoder address or results, check geocoder service can implemented using geocoder.ispresent()

if(geocoder.ispresent()){     //do stuff }else{    //cann't implement geocoder } 

happycoding;


Comments

Popular posts from this blog

javascript - Feed FileReader from server side files -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -