Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
36
rated 0 times [  41] [ 5]  / answers: 1 / hits: 16052  / 11 Years ago, mon, october 28, 2013, 12:00:00

Is it possible search multiple individual keywords in one place search request using Google Maps JavaScript API v3?



In the Google Places API documentation it states that multiple keywords can be used https://developers.google.com/places/training/additional-places-features



?keyword=theater+gym



but this does not work in the JavaScript API. I tried:



function performSearch() {
var request = {
location: map.center,
radius: '500',
keyword: 'theater+gym+tacos',
rankBy: 'distance'
};
service.radarSearch(request, callback);
}


...and does not return places for each keyword. Does anyone have an idea how to search multiple keywords?



Note: I'm trying to search multiple individual keywords in one request not a phrase with spaces.


More From » google-maps

 Answers
48

It looks like the answer is "no" (at least at the present time, you could request an enhancement on the issue tracker.


A work around would be to send three separate queries, one for each keyword. Should be OK for 3 keywords, at some point you will run into the query rate limit.


  var request = {
location: pyrmont,
radius: 500,
keyword: 'theater'
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
var request2 = {
location: pyrmont,
radius: 500,
keyword: 'gym'
};
var service2 = new google.maps.places.PlacesService(map);
service2.nearbySearch(request2, callback);
var request3 = {
location: pyrmont,
radius: 500,
keyword: 'tacos'
};
var service3 = new google.maps.places.PlacesService(map);
service3.nearbySearch(request2, callback);

proof of concept


code snippet:




var map;
var infowindow;

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

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

var request = {
location: pyrmont,
radius: 500,
keyword: 'theater'
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
var request2 = {
location: pyrmont,
radius: 500,
keyword: 'gym'
};
var service2 = new google.maps.places.PlacesService(map);
service2.nearbySearch(request2, callback);
var request3 = {
location: pyrmont,
radius: 500,
keyword: 'tacos'
};
var service3 = new google.maps.places.PlacesService(map);
service3.nearbySearch(request2, callback);
}

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

function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});

google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}

google.maps.event.addDomListener(window, 'load', initialize);

html,
body,
#map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}

<script src=https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&libraries=places></script>
<div id=map-canvas></div>




[#74693] Friday, October 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bobbyallanh

Total Points: 693
Total Questions: 120
Total Answers: 101

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
;