回答
这里是获取长期完整的代码 - 纬度,以获得地址:
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();
}
}
有时这种反向地理编码技术没有给出任何地址。所以每当我需要时,如何从lat-long获得地址? –
是的,它不会在某个时间返回地址。为此,您可以实施备份机制,例如,当您没有再次获取地址时获取地址,或者可以使用google api获取地址。 –
使用此权限:<使用权限android:name =“android.permission.ACCESS_COARSE_LOCATION”/> <使用权限android:name =“android.permission.ACCESS_FINE_LOCATION”/> –
您可以将我们的GeoCoder
在android.location中提供。 Geocoder
包。 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
将返回位置的名称。
在这里,我给了一个单一的只是通过经纬度在这个功能,然后你得到了所有与这个经度和纬度有关的信息。
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();
}
}
我希望你能解决你的答案。
- 1. 从坐标获取位置名称?
- 2. 获取从获取的坐标位置名称得到
- 3. 从坐标获取位置?
- 4. 如何从位置名称获取坐标
- 5. 从GPS坐标获取城市名称
- 6. 获取随机位置从坐标
- 7. 从UIButton获取位置坐标
- 8. 从经纬度获取位置名称
- 9. 从demangled名称获取错位名称
- 10. Android - 获取GPS坐标和位置
- 11. 获取用户位置坐标与MapKit
- 12. 无法获取当前位置坐标
- 13. Android 4.4.2 - 获取设备位置坐标
- 14. 获取ajax请求的位置坐标
- 15. 如何从街道名称,地名或城市名称获取GPS坐标
- 16. 如何从鼠标位置获取已翻译的坐标
- 17. dimple.js:获取坐标轴上的点/位置坐标
- 18. 根据给定的坐标在Windows Mobile中获取位置名称
- 19. 从坐标获取当前地点名称(在nsstring中)
- 20. 从坐标获取国家名称(使用CLLocationManager)
- 21. 如何从公司的商业名称中获取坐标?
- 22. 从谷歌地图中的地区名称获取坐标Api
- 23. android获取当前位置名称
- 24. 获取URL位置路径名称
- 25. 如何获取用户位置名称?
- 26. 通过邮编获取位置名称
- 27. 获取鼠标光标位置的windows组件名称
- 28. 按标记名称获取标记的位置
- 29. iOS核心位置 - 获取最准确的位置坐标
- 30. 从HashMap获取坐标
你在找这个“中给出-一个纬度和经度,得到最位置的名称] [1 ]” [1]:http://stackoverflow.com/questions/6172451/given-a-latitude-and-longitude-get-the-location-name – Samuel
看一看[如何编程谷歌Android](http://blogoscoped.com/archive/2008-12-15-n14.html) –
你的问题是相同的问题,我发布了几个月back..check此链接http:///stackoverflow.com/questions/6172451/given-a-latitude-and-longitude-get-the-location-name或检查我的答案下面... – Krishna