Get latitude and longitude based on city, zip or streetname

后端 未结 4 2102
悲&欢浪女
悲&欢浪女 2020-12-30 17:12

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?

Best Rega

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 17:44

    Check out the method Geocoder.getFromLocationName(cityName, maxResults).

    Use it like this:

    List
    addressList = geoCoder.getFromLocationName(cityName, 1); Address address = addressList.get(0); if(address.hasLatitude() && address.hasLongitude()){ double selectedLat = address.getLatitude(); double selectedLng = address.getLongitude(); }

提交回复
热议问题