Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Management Accounting

Authors: Charles Horngren, Gary Sundem, Jeff Schatzberg, Dave Burgsta

16th edition

978-0133058819, 9780133059748, 133058816, 133058786, 013305974X , 978-0133058789

More Books

Students also viewed these Accounting questions