android – 如何将GPS坐标转换为地点

前端之家收集整理的这篇文章主要介绍了android – 如何将GPS坐标转换为地点前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在编写一个 Android应用程序,将动态可用的纬度和逻辑坐标转换为人类可读的位置.

例如,12.2,4.5位于英国伦敦市中心.关于粒度,我希望能够至少找到城市 – >城镇.或者如果没有,至少在城市,

有人可以建议有什么解决方案可用于此问题.

解决方法

试试这个:
//listenner location changed
private class MyLocListener implements LocationListener {
   public void onLocationChanged(Location location) {
      if (location != null) {
         Log.d("LOCATION CHANGED",location.getLatitude() + "");
         Log.d("LOCATION CHANGED",location.getLongitude() + "");
      }
   }
}

 //Get address base on location
try{
 Geocoder geo = new Geocoder(youractivityclassname.this.getApplicationContext(),Locale.getDefault());
 List<Address> addresses = geo.getFromLocation(latitude,longitude,1);
  if (addresses.isEmpty()) {
        yourtextfieldname.setText("Waiting for Location");
  }
  else {
     if (addresses.size() > 0) {       
        Log.d(TAG,addresses.get(0).getFeatureName() + "," + addresses.get(0).getLocality() +"," + addresses.get(0).getAdminArea() + "," + addresses.get(0).getCountryName());

     }
  }
}
catch (Exception e) {
    e.printStackTrace(); 
}
原文链接:https://www.f2er.com/android/316915.html

猜你在找的Android相关文章