如何從我當前的位置在android中查找附近的城市或城鎮。我可以得到像ATM,醫院這樣最近的地方。但是,我無法獲得最近的城鎮名稱。從我當前所在的位置附近的城市或城鎮
3
A
回答
1
下面是一個例子:
private void updateWithNewLocation(Location location) {
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
String latLongString = "No location found";
String addressString = "No address found";
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Geocoder gc = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
} catch (IOException e) {}
}
myLocationText.setText("Your Current Position is:\n" +
latLongString + "\n\n" + addressString);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
+0
我只能從上面的代碼中獲得當前位置地址..我需要在10或15公里附近的城市或城鎮名稱。 – karthik
0
0
相關問題
- 1. 國家,城市和城鎮
- 2. 我怎樣才能從谷歌地圖最近的重要城鎮或城市?
- 3. 從flickr api提取城鎮/城市YQL
- 4. 如何從特定的城市獲取附近的城市?
- 5. 英國城鎮/城市的php數組
- 6. 城市附近城市Webservice或PHP代碼
- 7. 如何在python中獲取城市(geonameid)的附近城市?
- 8. 地理位置腳本,以確定當我在城市附近的城市評估爲假
- 9. 獲取城市/城鎮列表
- 10. 國家/城市/城鎮+計數列表
- 11. 我可以在哪裏找到用於基於位置的搜索的城市/城鎮位置數據?
- 12. 反向地理編碼 - 僅返回城鎮/城市或國家
- 13. 查找附近的大型城市GEONAMES
- 14. 如何在ios中獲取地理位置附近的城市或州名?
- 15. 猜猜城市的位置
- 16. 是否可以爲當前城市或家鄉設置城市列表?
- 17. 數據庫設計/性能 - 基於城市/城鎮位置按公司覆蓋
- 18. 如何到附近的景點或城市的興趣地點,位置
- 19. 使用javascript地理位置檢測當前城鎮名稱
- 20. Tableau:在地圖上標記城市和城鎮
- 21. 搜索附近城市lat和長
- 22. 當前城市爲零;
- 23. 如何查找某個城市駕車路程內的所有城鎮?
- 24. 搜索郵編或城鎮
- 25. 將城鎮/村莊分爲城市/社區
- 26. 確定是否在城市中或附近
- 27. 從城市獲取地理位置
- 28. 適用於城市,鄉鎮或村莊的任何API信息?
- 29. 可能通過Foursquare獲得我附近的城市嗎?
- 30. 如何爲城市城鎮標籤設置谷歌靜態地圖字體
您可以嘗試的地方API或從谷歌地圖API ...你有什麼已經嘗試過? –
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=lat,lng&radius=5000&types=food&sensor=true&key=APIKEY 我試過這個網址..我無法從這個城市獲得url – karthik
由於URL中的輸出顯示,您的API密鑰無效。在console.developers.google.com上生成一個新密鑰並嘗試使用該密鑰。 –