How to get latitude and longitude from a given address in android.
I want to get the latitude and longitude of a place from an address. I don't want to get the latitude and longitude from the GPS nor the the network.
How to get latitude and longitude from a given address in android.
I want to get the latitude and longitude of a place from an address. I don't want to get the latitude and longitude from the GPS nor the the network.
You can use below method:
// get latlng from address
public LatLng getLocationFromAddress(String strAddress) {
Geocoder coder = new Geocoder(context, Locale.getDefault());
List<Address> address;
LatLng p1 = null;
try {
address = coder.getFromLocationName(strAddress, 5);
if (address == null) {
return null;
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new LatLng(location.getLatitude(), location.getLongitude());
return p1;
} catch (Exception e) {
e.printStackTrace();
}
return p1;
}