【问题标题】:Get location name from fetched coordinates get the name从获取的坐标中获取位置名称获取名称
【发布时间】:2016-09-29 22:22:10
【问题描述】:

我找到了这个解决方案: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

【问题讨论】:

    标签: android gps location


    【解决方案1】:

    您在字符串_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);
    

    您可以使用此代码获取有关地址的更多信息

    【讨论】:

      猜你喜欢
      • 2011-10-18
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-17
      相关资源
      最近更新 更多