1
A
回答
1
Geocoder gcd = new Geocoder(context, Locale.getDefault());
try{
List<Address> addresses = gcd.getFromLocation(lat, lon, 1);//lat and lon is the latitude and longitude in double
if (addresses.size() > 0)
String cityName=addresses.get(0).getLocality();
}
catch (IOException e) {}
catch (NullPointerException e) {}
1
只要使用谷歌的API
http://maps.googleapis.com/maps/api/geocode/json?latlng=<LAT>,<LNG>&sensor=true
把你的經度和緯度在正確的地方並使用JSONObject來解析結果
0
試試這個,希望它有幫助。原諒這個循環,只是從我最近的一項工作中拿出來。
看看這個link。
Geocoder geocoder = new Geocoder(getApplicationContext(),Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude,longitude,1);
for(int i=0; i<addresses.size(); ++i)
{
address = addresses.get(i);
string city = address.getLocality();
}
0
可能是本文可能可以幫助你:http://www.devlper.com/2010/07/geocoding-and-reverse-geocoding-in-android/ 它還提供了它的源代碼。
否則,從here:
public class AndroidFromLocation extends Activity {
double LATITUDE = 37.42233;
double LONGITUDE = -122.083;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView myLatitude = (TextView)findViewById(R.id.mylatitude);
TextView myLongitude = (TextView)findViewById(R.id.mylongitude);
TextView myAddress = (TextView)findViewById(R.id.myaddress);
myLatitude.setText("Latitude: " + String.valueOf(LATITUDE));
myLongitude.setText("Longitude: " + String.valueOf(LONGITUDE));
Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);
try {
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
if(addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("Address:\n");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
myAddress.setText(strReturnedAddress.toString());
}
else{
myAddress.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
myAddress.setText("Canont get Address!");
}
}
}
此外,還要檢查這個具體的例子:http://www.smnirven.com/blog/2009/10/09/reverse-geocode-lookup-using-google-maps-api-on-android-revisited/和here獲得完整的代碼。
相關問題
- 1. 如何通過Facebook的城市ID查找城市名稱?
- 2. 如何從Java中的城市名稱中查找國家/地區名稱?
- 3. 搜索從PlaceAutoComplete城市名稱給人加密的城市名稱
- 4. 如何從城市名稱中查找經緯度
- 5. 將mapkit設置爲只有城市名稱的位置
- 6. 得到位置示範城市名單多少位置爲每個城市
- 7. 拼寫檢查城市名稱?
- 8. 獲取地理位置的城市名稱
- 9. 從GPS座標獲取城市名稱
- 10. 從城市名稱獲取經緯度
- 11. 從城市名稱獲取WOEID?
- 12. 從經緯度獲取城市名稱
- 13. 從CLLocationManager獲取城市名稱?
- 14. 城市名稱和國家/地區查找的API和服務
- 15. 如何在Android時刻查找城市和州的名稱?
- 16. 猜猜城市的位置
- 17. 如何在iphone中獲取地理位置城市名稱?
- 18. 只列出城市名稱Geocomplete.js或Google位置自動完成
- 19. 獲取當前位置和城市名稱Xamarin.Android
- 20. 使用經度和緯度查找城市和州名稱
- 21. 地理位置查找最近的城市
- 22. 在STATION中以最短和最長的城市名稱查詢兩個城市,
- 23. 從城市獲取地理位置
- 24. 從使用Java的tweet文本中查找城市,國家和公司名稱
- 25. 查找城市半徑
- 26. 自動城市查找器
- 27. 在Ruby中,如何查找城市白名單範圍內的城市?
- 28. 使用郵政編碼,城市或座標查找位置
- 29. 在城市環境中用iPhone查找位置
- 30. 來自gps的城市名稱
也許有些網絡服務? –
您需要GeoCoder類。 如果有幫助,請參閱此處。 [獲取當前位置的城市名稱] [1] [1]:http://stackoverflow.com/questions/18221614/how-i-can-get-the-city-name-of -My電流位置 – HexaHow