Question
For Java Android Studio, I need to display the address given the latitude and longitude (which I obtained in the onLocationChanged method). I tried the
For Java Android Studio, I need to display the address given the latitude and longitude (which I obtained in the onLocationChanged method). I tried the following method:
---------------------------------------------------------------------------------------------------------------------------------------------
public String getAddress(Context ctx, double lat, double lng){ String fullAdd=null; try{ Geocoder geocoder= new Geocoder(ctx, Locale.getDefault()); List addresses = geocoder.getFromLocation(lat, lng, 1); if(addresses.size()>0){ Address address = addresses.get(0); fullAdd = address.getAddressLine(0); } }catch(IOException ex){ ex.printStackTrace(); } return fullAdd; }
---------------------------------------------------------------------------------------------------------------------------------------------------
After that, in my onLocationChanged, I set a textview's text to
getAddress(this, location.getLatitude(), location.getLongitude());
However, I keep getting null for the address. How do I fix this and make it diplay the address given the latitude and longitude?
Step by Step Solution
3.38 Rating (157 Votes )
There are 3 Steps involved in it
Step: 1
Geocoder geocoder List addresses geocoder new Geocoderthis Loc...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started