get Lat Lang from a place_id returned by autocomplete place api

前端 未结 12 1451
情深已故
情深已故 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:08

    I got very simple solution to this problem thanks answer by Muhammad Yasir.

        List placeFields = Arrays.asList(Place.Field.LAT_LNG, Place.Field.ADDRESS_COMPONENTS);
        autocompleteFragment.setPlaceFields(placeFields);
    
        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                LatLng latLng = place.getLatLng(); // This will have required latitude and longitude
             }
       }
    

    You can specify any field you want as in the list like name, address etc.

    Note: This answer is for android java but I think there will be similar approach in other languages like javascript.

提交回复
热议问题