从获取的坐标获取位置名称

我有什么:目前我的应用程序只告诉我我当前位置的坐标。

我想要的:从GPS获取的坐标获取位置名称,以便我可以知道我到底在哪里。 (地点名称)

Solutions Collecting From Web of "从获取的坐标获取位置名称"

下面是从获取长地址到获取地址的完整代码:

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(); } } 

你可以使用我们在android.location中可用的GeoCoderGeocoder包。 JavaDocs给你充分的解释。 你可能的样本

  List<Address> list = geoCoder.getFromLocation(location .getLatitude(), location.getLongitude(), 1); if (list != null & list.size() > 0) { Address address = list.get(0); result = address.getLocality(); return result; 

result将返回该位置的名称。

在这里,我给了一个单一的只是通过经纬度在这个function,那么你得到所有的信息与这个经度和纬度。

 public void getAddress(double lat, double lng) { Geocoder geocoder = new Geocoder(HomeActivity.mContext, Locale.getDefault()); try { List<Address> addresses = geocoder.getFromLocation(lat, lng, 1); Address obj = addresses.get(0); String add = obj.getAddressLine(0); GUIStatics.currentAddress = obj.getSubAdminArea() + "," + obj.getAdminArea(); GUIStatics.latitude = obj.getLatitude(); GUIStatics.longitude = obj.getLongitude(); GUIStatics.currentCity= obj.getSubAdminArea(); GUIStatics.currentState= obj.getAdminArea(); add = add + "\n" + obj.getCountryName(); add = add + "\n" + obj.getCountryCode(); add = add + "\n" + obj.getAdminArea(); add = add + "\n" + obj.getPostalCode(); add = add + "\n" + obj.getSubAdminArea(); add = add + "\n" + obj.getLocality(); add = add + "\n" + obj.getSubThoroughfare(); Log.v("IGA", "Address" + add); // Toast.makeText(this, "Address=>" + add, // Toast.LENGTH_SHORT).show(); // TennisAppActivity.showDialog(add); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); } } 

我希望你能得到你的答案的解决scheme。