首页 文章

如何使用textsearch将距离与google places api按距离排序

提问于
浏览
4

我希望靠近我的位置订购所有餐馆 . 我正在使用google地址api使用textsearch:https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants&location=32.16107,34.806618&radius=200&sensor=true&key=api_key . 我得到的结果是稀疏的,没有任何顺序 . 我尝试了rankby = distance但是对于文档(https://developers.google.com/places/documentation/)你只能在常规搜索中使用它,这意味着当使用textsearch时没有这样的参数选项(我试过了)无论如何 - >不工作) . 我正在使用textsearch,因为常规搜索仅返回"types":["establishment"] . 我如何通过远程订购google place api的文本搜索?我可以't believe that google didn'创造一种方法来做到这一点......

1 回答

  • 6

    你是对的,Places API Textsearch不支持 rankBy=distance 参数 . 如果您认为这是一个有用的功能,请提交Places API Feature Request .

    但是,您可以通过使用 rankBy=distance 参数和 keyword=restaurant 参数执行Places API搜索请求来获取您要查找的结果:

    https://maps.googleapis.com/maps/api/place/search/json?keyword=restaurant&location=32.16107,34.806618&rankBy=distance&sensor=false&key=YOUR_API_KEY

    keyword 参数与所有可用字段匹配,包括但不限于名称,类型和地址,以及客户评论和其他第三方内容 .

相关问题