問(wèn)題描述
我需要知道是否有任何 API,我可以從那里接收當(dāng)前地點(diǎn)的地址.使用位置管理器我已經(jīng)收到了當(dāng)前地點(diǎn)的緯度和經(jīng)度,但我需要地址.
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.
我已經(jīng)嘗試了下面的 api.
I have tried the below api.
http://maps.googleapis.com/maps/api/geocode/json?latlng="+ lat + "," + lon + &sensor=true"
但它沒(méi)有顯示確切的位置.有人可以幫助我嗎.@謝謝
But it is not showing the exact place .Can somebody help me.@Thanks
推薦答案
來(lái)自 Geocoder 對(duì)象,可以調(diào)用 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();
}
另一個(gè)最佳答案在這里 如何從谷歌地圖的經(jīng)緯度坐標(biāo)中獲取城市名稱?
Another best answer is here How to get city name from latitude and longitude coordinates in Google Maps?
這篇關(guān)于使用緯度和經(jīng)度獲取特定地址的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!