use*_*953 3 java android android-widget android-emulator
在我目前的Android应用程序中,我想根据输入的城市名称,街道名称或邮政编码获取地理坐标.我怎么能做到这一点?
最诚挚的问候,Rony
看看方法Geocoder.getFromLocationName(cityName, maxResults).
像这样使用它:
List<Address> addressList = geoCoder.getFromLocationName(cityName, 1);
Address address = addressList.get(0);
if(address.hasLatitude() && address.hasLongitude()){
double selectedLat = address.getLatitude();
double selectedLng = address.getLongitude();
}
Run Code Online (Sandbox Code Playgroud)
您好,尝试以下代码从给定的地址获取Geocode点.
List<Address> 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
Run Code Online (Sandbox Code Playgroud)