使用Google地图API获取相关(而非伪随机)结果 [英] Getting relevant (rather then pseudo-random) results with google maps places API

查看:115
本文介绍了使用Google地图API获取相关(而非伪随机)结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了关于Places API的所有帖子(这里和其他地方),但仍无法找到解决方案。我有一个表格,用户可以输入街道号码或建筑物名称(如商场)。我想在提交和显示地图之前通过地理编码(如果是数字)或地点(如果它是名称)验证信息,因为我需要确切的地址,但是地点搜索给了我伪随机结果。例如:

I read all the posts (here and elsewhere) about the Places API and still can't find a solution. I have a form in which the user can input the street and either the number or the building name (like a mall). I want to validate the info via geocode (if it's a number) or places (if it's a name) before submitting and showing the map as I need the exact address, but the Places search gives me pseudo-random results. For example:

var cityCenter = new google.maps.LatLng(1.30563, 103.83751);
var building = 'Forum';
places = new google.maps.places.PlacesService(map); 
places.search({ location: cityCenter, radius:'50000', query:building }, function(results, status) 
{
    console.log(results);
});

maps.google.com上的第一个结果是完美的。实际上,前几个结果是相关的或者至少包含'论坛'这个词。在我的应用程序中,我得到了20个与我的查询没有远程相关的结果。

The first result on maps.google.com is perfect. Actually the first several results are relevant or at least contain the 'Forum' word. In my app I get 20 results that are not remotely related (apparently) to my query.

有什么方法可以获得与网站相同的结果?

Is there any way I can get the same results as the website?

推荐答案

您似乎在尝试使用 places.textSearch 服务,因为您使用查询参数,但是您要调用 places.search

It appears that you are trying to use the places.textSearch service as you are using the query parameter, however you are calling the places.search service.

试试:

places.textSearch({ location: cityCenter, radius:'50000', query:building }, function(results, status) 
{
    console.log(results);
});

这篇关于使用Google地图API获取相关(而非伪随机)结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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