Reputation: 27
Trying to fetch all the restaurants within a city using Google Places API. Even though there are 100 records returned, only 20 markers are displayed on map. Below is the piece of code where we are creating markers. Please tell me if I am missing something here. You may refer to below link and give input as restaurants in a 'Santa Clara' jsfiddle.net/r8g42046
//function used to create marker based on Location of a place.
function createMarker(place){
var place = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(place.name);
infoWindow.open(map, this);
});
}
// Callback function based on results fetched from Places library based on type : restaurant.
function callback(results, status, next_page_token) {
if (results != null){
resultlist.push(results);
}
if (next_page_token != undefined){
textSearchrequest.pagetoken = next_page_token;
service.textSearch(textSearchrequest,callback);
}
else{
findLocation(resultlist[0][0].place_id);
for(var page = 0;page < resultlist.length;page++)
{
for (var i = 0; i < resultlist[page].length; i++) {
var place = resultlist[page][i];
console.log(place.name); // Displays 100 restaurant names
createMarker(place); //Call create marker function
}
}
}
}
Upvotes: 0
Views: 1062
Reputation: 117324
This line is completely useless:
textSearchrequest.pagetoken = next_page_token;
pagetoken
is a URL-parameter for the places-webservice and has no meaning in the places-library
it will not lead you to the next page of results.
You always get the same set of(20) results and draw the same set of markers again and again, until you hit the QUERY_LIMIT. When you hit the QUERY_LIMIT after 10 requests, you draw 200, when you hit it after 12 request 240, but no matter how often you may run the search, you never get more than 20 different places(markers)
Although you draw 200 (or more)markers you only see 20 markers, because they are at the same locations.
Use the method pagination.nextPage() to access the next set of results.
Upvotes: 1