How to get latitude & longitude from given address on Android?
I want to get latitude and longitude of particular add开发者_如何学Pythonress . How can i do this ?
This is the sample solution to your question.
OR
List<Address> foundGeocode = null;
/* find the addresses by using getFromLocationName() method with the given address*/
foundGeocode = new Geocoder(this).getFromLocationName("address here", 1);
foundGeocode.get(0).getLatitude(); //getting latitude
foundGeocode.get(0).getLongitude();//getting longitude
For more details Geocoder
public List<Address> getFromLocationName (String locationName, int maxResults)
From a Geocoder
object, you can call the getFromLocation
public List<Address> getFromLocation (double latitude, double longitude, int maxResults)
It will return a list of Address object that has a method getLocality
Geocoder gcd = new Geocoder(context, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(lat, lng, 1);
if (addresses.size() > 0)
System.out.println(addresses.get(0).getLocality());
for more detail
show the location in google map from address...will get the latitude and longitude using the address...
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;
strAddress is string that you pass of address. address variable is address converting and getting address.
精彩评论