根据城市,邮编或街道名称获取纬度和经度
在我当前的Android应用程序中,我想根据输入的城市名称,街道名称或邮政编码获取地理坐标。 我怎么能做到这一点?
最诚挚的问候,Rony
查看方法Geocoder.getFromLocationName(cityName, maxResults)
。
像这样用它:
List addressList = geoCoder.getFromLocationName(cityName, 1); Address address = addressList.get(0); if(address.hasLatitude() && address.hasLongitude()){ double selectedLat = address.getLatitude(); double selectedLng = address.getLongitude(); }
您好,请尝试以下代码从给定地址获取Geocode点。
List foundGeocode = null; /* find the addresses by using getFromLocationName() method with the given address*/ foundGeocode = new Geocoder(this).getFromLocationName("address here", 1); foundGeocode.get(0).getLatitude(); //getting latitude foundGeocode.get(0).getLongitude();//getting longitude
嗨,
有一个非常好的网站叫做世界地名录,它有你需要的数据,整齐,可下载的文件(按城市名称)
http://www.world-gazetteer.com/home.htm
在主页面上,单击指向以下内容的链接:
其他统计数据…..各种统计数据:表格,地图和可下载的数据
从出现的页面中,单击指示的链接:
popdata(1.4 MB)
解压缩文件,你就搞定了!
该数据库是世界城市的免费主数据库,包括纬度,经度和人口数据等。
来自以下url : http : //answers.google.com/answers/threadview?id = 432778
尝试这个。
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); try { List addresses = geoCoder.getFromLocation(latitude , longitude, 1); String strCompleteAddress= ""; //if (addresses.size() > 0) //{ for (int i=0; i ", strCompleteAddress); Toast.makeText(getBaseContext(), strCompleteAddress, Toast.LENGTH_LONG).show(); } catch (IOException e) { Log.i("MyLocTAG => ", "this is the exception part"); e.printStackTrace(); }