谷歌放置自动完成 - 位置和半径不起作用 [英] Google places autocomplete - location and radius not working

查看:20
本文介绍了谷歌放置自动完成 - 位置和半径不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

查看文档

它说:

半径 |定义返回地点结果的距离(以米为单位).最大允许半径为 50 000 米.请注意,如果指定了 rankby=distance(在下面的可选参数中描述),则不能包括半径.

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:

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

排名|距离.此选项按与指定位置的距离按升序对结果进行排序.按距离排序的结果将设置一个固定的搜索半径为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆