get Lat Lang from a place_id returned by autocomplete place api

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

    Each place returned in the place-autocomplete response has an Id and a reference string as explained here.

    Use either (preferably Id since reference is deprecated) to query Places API for the full information about that place (including lat/lng): https://developers.google.com/places/documentation/details#PlaceDetailsRequests

    Regarding shyam's comment - Geocoding will work only if you got a full address in the autocomplete response which is not always the case. Also Geocoding gives a list of possible results since the place description you get in the autocomplete response is not unique. Depending on your needs, geocoding might be enough.

提交回复
热议问题