2016-09-29 139 views
0

我发现这个解决方案的名称:here获得位置的名字,但我不知道如何显示它我textView获取从获取的坐标位置名称得到

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(); 
    t.append("\n " + ????? + " "); 
} 

} 

的t是textView

回答

2

您在字符串_Location中有姓名地址。因此,您可以在try块中设置值TextView

try { 
List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1); 
if(null!=listAddresses&&listAddresses.size()>0){ 
    String _Location = listAddresses.get(0).getAddressLine(0); 
} 
t.setText(_Location); 
} 

进一步信息来源

String address1 = listAddresses.get(0).getAddressLine(0); 
    String city = listAddresses.get(0).getLocality(); 
    String state = listAddresses.get(0).getAdminArea(); 
    String country = listAddresses.get(0).getCountryName(); 
    String postalCode = listAddresses.get(0).getPostalCode(); 
    String knownName = listAddresses.get(0).getFeatureName(); 

    t.setText(address1 + " " + city + "\n" + state + " " + postalCode); 

你可以使用此代码来获取有关ADRESS

+0

这项工作就像魔术HAHAH更多信息,感谢的人很多 – user3670592