Getting relevant (rather then pseudo-random) results with google maps places API

拥有回忆 提交于 2019-12-25 05:04:59

问题


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);
});

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?


回答1:


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.

Try:

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


来源:https://stackoverflow.com/questions/11355256/getting-relevant-rather-then-pseudo-random-results-with-google-maps-places-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!