获得从获取的坐标位置名称
问题描述:
我有什么:目前我的应用程序只告诉我,我目前所在位置的坐标
What i have: currently my app is only telling me the coordinates of my current location.
我要的是:获取位置名称由GPS获取的坐标,这样我就可以知道究竟我是。 (地点名称)
What i want: Get location name from coordinates fetched by gps, so that i could know where exactly i am. (Name of location)
答
下面是获取长期完整的code - 纬度,以获得地址:
Here is complete code from fetching long - lat to getting address:
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
String provider = locationManager.getBestProvider(new Criteria(), true);
Location locations = locationManager.getLastKnownLocation(provider);
List<String> providerList = locationManager.getAllProviders();
if(null!=locations && null!=providerList && providerList.size()>0){
double longitude = locations.getLongitude();
double latitude = locations.getLatitude();
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1);
if(null!=listAddresses&&listAddresses.size()>0){
String _Location = listAddresses.get(0).getAddressLine(0);
}
} catch (IOException e) {
e.printStackTrace();
}
}