回答
這裏是獲取長期完整的代碼 - 緯度,以獲得地址:
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