【问题标题】:searchBox Google Maps with paginationsearchBox 谷歌地图分页
【发布时间】:2016-11-14 13:48:18
【问题描述】:

所以我要做的是使用搜索框实现 Google 地图。目前,搜索框会根据搜索结果检索 20 个排名靠前的地方。

我注意到这里没有分页。例如,如果我输入“pizza”,它将为我提供当前位置范围内的前 20 个结果。但是当我使用google.maps.places.PlacesService(map) textSearch 函数获取披萨搜索列表时,我得到了超过 20 个带有分页的结果。

有没有办法在你的 searchBox 上获得分页或在你使用 searchBox 后使用 textSearch 功能提供分页?

我这里有一个sn-p:

var canvas = element.find('div')[0];
var mapOptions = {
    zoom: 5,
    minZoom: 2,
};
var searchBox = new google.maps.places.SearchBox('pizza');
var placeService = new google.maps.places.PlacesService(map);

google.maps.event.addListener(searchBox, 'places_changed', locationChange);

function locationChange() {
    var places = searchBox.getPlaces();
    //Determine if there are additional places not provided by searchbox. Using text 
    var request = {
        query: input.value,
    };
    var textSearchPlaces = placeService.textSearch(request, callback);
    function callback(results, status, pagination) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {
            var hi = places;
            for (var i = 0; i < results.length; i++) {
                var place = results[i];
            }
        }
    }
    if (places.length === 0) {
        return;
    }
};

如您所见,这不是使用分页查找的最理想解决方案,因为我必须过滤 textSearchPlaces 以查看这些位置是否与 searchBox 结果不重复。

我还考虑过只删除 searchBox 并使用 textSearch 功能,但我意识到我不会拥有提供 searchBox 提供的建议的 autoComplete 功能。

【问题讨论】:

  • 完全忽略搜索框返回的地点,只根据&lt;input&gt;的值运行一个textSearch
  • 嗯,这是一种有趣的方式,哈哈。

标签: javascript google-maps google-maps-api-3 pagination


【解决方案1】:

您很可能收到OVER_QUERY_LIMIT

if (status == google.maps.places.PlacesServiceStatus.OK) {

在完成所有列表后尝试将details requests 排队,添加相同的超时逻辑以检查此行上的google.maps.places.PlacesServiceStatus.OVER_QUERY_LIMIT

if (pagination.hasNextPage) {
//add all places to the list
setTimeout('pagination.nextPage()',2000);
}  else {
createMarkers(placesList);
}

在使用 Places 时,您应该使用 google.maps.places.PlacesServiceStatus.OVER_QUERY_LIMIT

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多