假设我有某个位置的经度和纬度。我可以检索位置的名称吗?比如 jet's pizza 或 walmart...
最佳答案
这里是完整的定位方法。 只需从任何地方调用它。 您将获得用户的当前位置。具有完整的街道、城市和国家/地区地址
您还可以将纬度和经度值传递给 . addresses = gcd.getFromLocation(latitude, longitude, 1);
获取任何特定值的位置。
public String getUserLocation() {
String address = "";
LocationManager locManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
boolean network_enabled = locManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Location location;
if (network_enabled) {
location = locManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
double longitude = location.getLongitude();
double latitude = location.getLatitude();
Log.e("longitude = ", longitude + "lat");
Log.e("latitude = ", latitude + "long");
Geocoder gcd = new Geocoder(context, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = gcd.getFromLocation(latitude, longitude, 1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return address;
}
if (addresses.size() > 0) {
String addressline = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
Log.e("Address", addressline + ", " + city + ", " + country);
return address = addressline + ", " + city + ", " + country;
}
return address;
}
}
return address;
}
希望这有帮助:)
关于java - 如何在android中获取位置名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20990454/