谷歌则以自动完成 - 位置和半径不工作 [英] Google places autocomplete - location and radius not working
问题描述
我试着设置谷歌的地方自动完成从最近的一个点对结果进行排序。我有一个code这样的...
Im trying to set the google places autocomplete to sort the results from the nearest to a point. I have a code like this...
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的伟大工程,但位置和半径似乎并不奏效。
the types and componentRestrictions works great but the location and radius doesn't seems to be working.
推荐答案
看文档
它指出:
半径|定义之内返回商家结果的距离(米)。允许的最大半径为50000米。注意如果rankby =指定的距离(根据下文的可选参数说明)的半径必须不包括在内。
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 =距离:
It sound like you want the optional parameter: rankby=distance:
rankby |距离。这个选项排序从指定位置的距离导致升序排列。按距离排序结果将设置50公里的固定搜索半径。的一个或多个关键字,名称或类型是必需的。
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的服务
这篇关于谷歌则以自动完成 - 位置和半径不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!