[英]Google Maps v3 - How can I get all the markers?
使用此代码,我可以在地图上仅显示通过研究获得的前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);
但是我会在地图上同时显示所有标记,而不仅仅是前20个。 我怎样才能做到这一点?
您必须在回调中寻找第三个参数:
function callback(results, status, pagination)...
该对象可以说是否还有更多结果:
if (pagination.hasNextPage) {
button.onClick = pagination.nextPage;
}
您必须确定调用下一页的逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.