google-maps-api-3 - 谷歌放置自动完成 - 位置和半径不起作用

标签 google-maps-api-3 autocomplete google-places-api

我试图设置谷歌地点自动完成以从最近到一个点对结果进行排序。我有一个这样的代码...

var defaultPlace = new google.maps.LatLng(49.227463, 16.546097);

var optionsAuto = {
    location: defaultPlace,
    radius: 20000,
    types: ['geocode'],
    componentRestrictions: {
        country: 'cz'
    }
};

var autocomplete = new google.maps.places.Autocomplete( inputStart, optionsAuto );

类型和 componentRestrictions 效果很好,但位置和半径似乎不起作用。

最佳答案

documentation

它指出:

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.



听起来你想要可选参数: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.



也可在 javascript service 中找到

Working Example

关于google-maps-api-3 - 谷歌放置自动完成 - 位置和半径不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11810810/

相关文章:

c# - 将 Javascript 用于 WPF 中的 Google map API

java - 将 AutoCompleteTextView 预测仅限于餐馆

javascript - 谷歌地图响应调整大小

google-maps - Google 将自动完成功能放置在 React 组件中

javascript - 如何减少 Chosen Javascript Autocomplete 中的最大建议数量?

javascript - 使用 ExtJs 自动完成文本字段

c# - 使用嵌套的elasticsearch自动完成映射

google-places-api - Google Places 自动完成国家/地区限制

google-maps-api-3 - Google Places API - 查找最近的地点、距离和旅行时间

google-maps-api-3 - 如何更改 map (而不是标记)的 Google map 可拖动属性?