【发布时间】:2015-10-09 00:23:43
【问题描述】:
尝试使用 Google Places API 获取城市内的所有餐厅。 即使返回了 100 条记录,地图上也只显示了 20 个标记。 下面是我们创建标记的一段代码。如果我在这里遗漏了什么,请告诉我。您可以参考以下链接并在“Santa Clara”jsfiddle.net/r8g42046 中作为餐厅提供输入
//用于根据地点的位置创建标记的函数。
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
}
}
}
}
【问题讨论】:
-
请提供一个Minimal, Complete, Tested and Readable example 来证明该问题。什么是查询?你在使用radarSearch、textSearch...吗?
-
您可以参考下面的链接并在jsfiddle.net/r8g42046 的地方作为餐厅提供输入。它返回 100 条记录,但您只能看到 20 个显示的标记。使用文本搜索。
-
注意,textSearch 仅限于 20 个结果。你在哪里看到 100 条记录? From the documentation:“默认情况下,每个地点搜索每个查询最多返回 20 个结果。但是,每个搜索最多可以返回 60 个结果,分成三个页面。”
标签: javascript google-maps google-places-api