how to find latitude and longitude by getting location name or pin-code address as input using Google map in android example in edit-text i enter a city name or city pin-code it will show the latitude and longitude of it.
Asked
Active
Viewed 229 times
2 Answers
1
please check this one this will be helpful to you get latitude and longitude from city name or How can I find the latitude and longitude from address?
1
This is a much simpler solution, assuming the geocoder services are present:
final Geocoder geocoder = new Geocoder(this);
final String zip = "90210";
try {
List<Address> addresses = geocoder.getFromLocationName(zipCode, 1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
// Use the address as needed
String message = String.format("Latitude: %f, Longitude: %f",
address.getLatitude(), address.getLongitude());
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
} else {
// Display appropriate message when Geocoder services are not available
Toast.makeToast(this, "Unable to geocode zipcode", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
// handle exception
}
//addr
Geocoder coder = new Geocoder(this);
List<Address> address;
try {
address = coder.getFromLocationName(strAddress,5);
if (address == null) {
return null;
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new GeoPoint((int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
return p1;
}
http://android-er.blogspot.in/2011/02/get-address-from-location-using.html
Jatinkumar Patel
- 1,693
- 2
- 15
- 35