本文介紹了使用緯度和經度獲取特定地址的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我需要知道是否有任何 API,我可以從那里接收當前地點的地址.使用位置管理器我已經收到了當前地點的緯度和經度,但我需要地址.
I need to know is there any API ,from where i can receive the Address of the current place.Using location Manager i have receive the latitude and longitude of the current place ,but i need the address.
我已經嘗試了下面的 api.
I have tried the below api.
http://maps.googleapis.com/maps/api/geocode/json?latlng="+ lat + "," + lon + &sensor=true"
但它沒有顯示確切的位置.有人可以幫助我嗎.@謝謝
But it is not showing the exact place .Can somebody help me.@Thanks
推薦答案
來自 Geocoder 對象,可以調用 getFromLocation(double, double, int) 方法.
From a Geocoder object, you can call the getFromLocation(double, double, int) method.
喜歡:-
private String getAddress(double latitude, double longitude) {
StringBuilder result = new StringBuilder();
try {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
result.append(address.getLocality()).append("
");
result.append(address.getCountryName());
}
} catch (IOException e) {
Log.e("tag", e.getMessage());
}
return result.toString();
}
另一個最佳答案在這里 如何從谷歌地圖的經緯度坐標中獲取城市名稱?
Another best answer is here How to get city name from latitude and longitude coordinates in Google Maps?
這篇關于使用緯度和經度獲取特定地址的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!