Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google map: how to get address in android

How to get the location or address from the google map when i am click on a particular address. IS it possible to use map overlay to collect the address from the map view.

like image 764
Akhil Avatar asked Dec 16 '22 16:12

Akhil


1 Answers

Please Use below code for get address.

try {
    Geocoder geo = new Geocoder(youractivityclassname.this.getApplicationContext(), Locale.getDefault());
    List<Address> addresses = geo.getFromLocation(latitude, longitude, 1);
    if (addresses.isEmpty()) {
        yourtextfieldname.setText("Waiting for Location");
    }
    else {
        if (addresses.size() > 0) {
            yourtextfieldname.setText(addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName());
            //Toast.makeText(getApplicationContext(), "Address:- " + addresses.get(0).getFeatureName() + addresses.get(0).getAdminArea() + addresses.get(0).getLocality(), Toast.LENGTH_LONG).show();
        }
    }
}
catch (Exception e) {
    e.printStackTrace(); // getFromLocation() may sometimes fail
}

And see below link for more information and complete example.

Using Google Maps in Android

like image 196
Dipak Keshariya Avatar answered Jan 05 '23 23:01

Dipak Keshariya