根据城市、邮编或街道名称获取纬度和经度

在我当前的 android 应用程序中,我想根据输入的城市名称、街道名称或邮政编码获取地理坐标.我怎样才能做到这一点?

In my current android application, I would like to get the geocordinates based on an entered city name, street name or zip code. How can I accomplish this?

最好的问候,罗尼

推荐答案

查看方法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();
}

相关文章