0

I have been unable to test my code on an emulator as Ive come to understand you cannot use geolocate on an emulator. Thus I'm not sure if Im initializing / using the functions utilities properly.

(I want to geolocate my phone, and print via a TextView the closest known address to my lat/lon fix)

Heres my code:

Location location;
Geocoder geocoder;
TextView Address;

private OnClickListener OnClick = new OnClickListener(){
    public void onClick (View src){

        double latitude = location.getLatitude();
        double longitude = location.getLongitude();

        if (longitude != 0 && latitude != 0){
            try {
                List<Address> list  = geocoder.getFromLocation(latitude, longitude, 1);
                Address address = list.get(0);          
                StringBuilder sb = new StringBuilder();
                sb.append(address);
                String addressString = sb.toString();
                Address.setText(addressString);
            } catch (IOException e) {}
        }
    }
};
Reno
  • 33,594
  • 11
  • 89
  • 102
Adam Storm
  • 724
  • 1
  • 6
  • 13

1 Answers1

0

You can look at this :How to emulate GPS location on the android emulator

Community
  • 1
  • 1
Rasel
  • 15,499
  • 6
  • 40
  • 50