get Lat Lang from a place_id returned by autocomplete place api

前端 未结 12 1599
情深已故
情深已故 2021-02-02 05:58

I am searching the place in my apps using the google autocomplete place api and now I want to get latitude and longitude of the place that i have searched. How to get latitude a

12条回答
  •  轮回少年
    2021-02-02 06:17

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    
       if (requestCode == Constant.REQUEST_LOCATION_CODE) {
    
            Place place = PlaceAutocomplete.getPlace(this, data);
    
            if (place != null) {
                LatLng latLng = place.getLatLng();
                mStringLatitude = String.valueOf(latLng.latitude);
                mStringLongitude = String.valueOf(latLng.longitude);
                EditTextAddress.setText(place.getAddress());
            }
        }
    }
    

    With the code above, you can get the LatLng as well as the String address. Use the LatLng wherever you want.

提交回复
热议问题