[英]How to get latitude & longitude from given address on Android?
I want to get latitude and longitude of particular address . 我想获得特定地址的纬度和经度。 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
public List<Address> getFromLocationName (String locationName, int maxResults)
From a Geocoder
object, you can call the getFromLocation
在Geocoder
对象中,您可以调用getFromLocation
public List<Address> getFromLocation (double latitude, double longitude, int maxResults)
It will return a list of Address object that has a method getLocality
它将返回具有方法getLocality
的Address对象的列表
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());
show the location in google map from address...will get the latitude and longitude using the address... 在地址中显示google map中的位置...将使用该地址获取经度和纬度...
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. strAddress是您传递地址的字符串。 address variable is address converting and getting address. 地址变量是地址转换和获取地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.