RK12
RK12

Reputation: 472

Can i get the exact results as like google by passing just keyword?

I want to search places by keyword match.

I have used Google Map Places API for this and passed the following arguments for search in this name is dynamically added from search textbox.

  var search = {
          bounds: map.getBounds(),
          keyword:[name] //name=dentist

        };

I am getting results in this but these results are not same as I got from google search.

Suppose if I enter dentist and choose location Ahmadabad in auto complete then I need the search results exactly as I search "dentist in ahmedabad" in google.

Is it possible to get same results as google? Help will be appreciated.

Upvotes: 0

Views: 1019

Answers (1)

Mr.Rebot
Mr.Rebot

Reputation: 6791

Check Places Library:

The functions in the Google Places JavaScript library enable your application to search for places (defined in this API as establishments, geographic locations, or prominent points of interest) contained within a defined area, such as the bounds of a map, or around a fixed point.

In your case use Text Search Requests:

The Google Places Text Search service is a web service that returns information about a set of places based on a string — for example "pizza in New York" or "shoe stores near Ottawa". The service responds with a list of places matching the text string and any location bias that has been set. The search response will include a list of places. You can send a Place Details request for more information about any of the places in the response.

Text Searches are initiated with a call to the PlacesService's textSearch() method.

service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);

You must also pass a callback method to textSearch(), to handle the results object and a google.maps.places.PlacesServiceStatus response.

var map;
var service;
var infowindow;

function initialize() {
  var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);

  map = new google.maps.Map(document.getElementById('map'), {
      center: pyrmont,
      zoom: 15
    });

  var request = {
    location: pyrmont,
    radius: '500',
    query: 'restaurant'
  };

  service = new google.maps.places.PlacesService(map);
  service.textSearch(request, callback);
}

function callback(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      var place = results[i];
      createMarker(results[i]);
    }
  }
}

Hope it helps!

Upvotes: 2

Related Questions