How can I find the latitude and longitude from address?

前端 未结 9 1162
礼貌的吻别
礼貌的吻别 2020-11-22 10:27

I want to show the location of an address in Google Maps.

How do I get the latitude and longitude of an address using the Google Maps API?

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 11:05

    The following code will work for google apiv2:

    public void convertAddress() {
        if (address != null && !address.isEmpty()) {
            try {
                List
    addressList = geoCoder.getFromLocationName(address, 1); if (addressList != null && addressList.size() > 0) { double lat = addressList.get(0).getLatitude(); double lng = addressList.get(0).getLongitude(); } } catch (Exception e) { e.printStackTrace(); } // end catch } // end if } // end convertAddress

    Where address is the String (123 Testing Rd City State zip) you want to convert to LatLng.

提交回复
热议问题