geocoder.getFromLocation returning null
11,580
I find the solution...
hold Ctrl
on getFromLocation()
and go to Geocoder.class
.
then download sources for your android API and restart your project.
then you see its work
Author by
piyush
Updated on June 04, 2022Comments
-
piyush almost 2 years
my code :
try { Geocoder geocoder; List<Address> addresses; geocoder = new Geocoder(LocationActivity.this, Locale.getDefault()); addresses = geocoder.getFromLocation(longitude,latitude,1); Toast.makeText(LocationActivity.this, addresses.size() + "", Toast.LENGTH_LONG).show(); String address = addresses.get(0).getAddressLine(0); String city = addresses.get(0).getAddressLine(0); String country = addresses.get(0).getAddressLine(0); Toast.makeText(LocationActivity.this, address + " " + city + " " + country, Toast.LENGTH_LONG).show(); } catch(Exception e) { Toast.makeText(LocationActivity.this,e.toString(), Toast.LENGTH_LONG).show(); }
this is my code to get address from longitude and latitude. but every time addresses.size returns 0
can anyone help me for this
-
Sandeep P over 11 yearscheck your lat long valid or not
-
piyush over 11 yearsi checked it... and its valid
-
Sandeep P over 11 yearsfinally try with targetsdk version 15
-
piyush over 11 yearsnope... whats thats... can u give a full description.. my api is 8 and android 2.2
-
piyush over 11 yearsnope.. i m not getting any exception... but addresses size always 0
-
piyush over 11 yearsbut i m creating my application in targetsdk 8 (2.2)... now what i have to do ??
-
Sandeep P over 11 yearsRight click on project, go to properties(in the end), select the android at right side , select project-build target (sel max) which contain google, and mention this in manifest <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> ..... if still it is not working , may be ur device fault
-
piyush over 11 yearsbut my device have android 2.2 OS.. if i change target then still i can run this app in android 2.2 ?
-
Sandeep P over 11 yearsyes u can run it, target sdk is not a matter make sure that min sdk is 8 so u can run in 2.2
-
Sandeep P over 11 years<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
-
piyush over 11 yearsi change the target to 15 and i tried to other device... still not working... still its give arrayIndexOutofBound Exception..
-
Ajay Pandya almost 9 yearshave you start location access from settings
-
John Hughes over 5 yearsso how to install the backend service