使用此代码我可以在地图上显示通过研究获得的前20个标记。
function initialize() {
google.maps.visualRefresh = true;
var mapOptions = {
center: new google.maps.LatLng(41.900233,12.482132),
zoom: 12,
minZoom: 12,
maxZoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
var allowedBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(41.77336,12.338805),
new google.maps.LatLng(42.046233,12.675261)
);
var request = {
bounds: allowedBounds,
query: "ristorante"
};
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]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
但我会在地图上同时显示所有标记,而不仅仅是前二十个标记。我怎么能这样做?
答案 0 :(得分:0)
您必须在回调中查找第三个参数:
function callback(results, status, pagination)...
该对象可以说是否有更多结果:
if (pagination.hasNextPage) {
button.onClick = pagination.nextPage;
}
你必须决定调用下一页的逻辑。