chris
chris

Reputation: 649

Getting relevant (rather then pseudo-random) results with google maps 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);
});

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?

Upvotes: 0

Views: 608

Answers (1)

Chris Green
Chris Green

Reputation: 4425

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

Upvotes: 1

Related Questions