获得从获取的坐标位置名称 [英] Get location name from fetched coordinates
本文介绍了获得从获取的坐标位置名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有什么:目前我的应用程序只告诉我,我目前所在位置的坐标
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();
}
}
这篇关于获得从获取的坐标位置名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文