I have a requirement that whenever I drag/browse the Google map and place a marker on it, it should display the name of the place(where the marker is placed) in an AutocompleteTextview. I have checked out the Places API and the Geocoder class but i least understood it. I need to do the task same as that of the Places tab in the life360 app. How can I achieve it?
For that click on the style option just below layer name. Now change the set label option to name or description to display it.
try this it may help you...
When u mark a place, try to capture latitude & longitude with marker & use this code to get location name
public String getAddress(Context context, double lat, double lng) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
add = add + "\n" + obj.getCountryName();
add = add + "\n" + obj.getCountryCode();
add = add + "\n" + obj.getAdminArea();
add = add + "\n" + obj.getPostalCode();
add = add + "\n" + obj.getSubAdminArea();
add = add + "\n" + obj.getLocality();
add = add + "\n" + obj.getSubThoroughfare();
return add;
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
return null;
}
}
Try this I hope Its work.
public void getLocation(double lat, double lng) {
Geocoder geocoder = new Geocoder(MapsActivity.this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
Log.e("IGA", "Address" + add);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With