Google places autocomplete - location and radius not working

前端 未结 3 1412
谎友^
谎友^ 2021-01-12 21:52

Im trying to set the google places autocomplete to sort the results from the nearest to a point. I have a code like this...

         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 22:42

    Look at the documentation

    It states:

    radius | Defines the distance (in meters) within which to return Place results. The maximum allowed radius is 50 000 meters. Note that radius must not be included if rankby=distance (described under Optional parameters below) is specified.

    It sound like you want the optional parameter: rankby=distance:

    rankby | distance. This option sorts results in ascending order by their distance from the specified location. Ranking results by distance will set a fixed search radius of 50km. One or more of keyword, name, or types is required.

    Which is also available in the javascript service

    Working Example

提交回复
热议问题