谷歌的演示有一个片段,通过分页捕获来自地方搜索的20多个结果:
service.nearbySearch(request, resultList, function(status, results, pagination) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
return;
}
resultList.addPlaces(results);
if (pagination.hasNextPage) {
resultList.button.onClick = pagination.nextPage;
}
});
Run Code Online (Sandbox Code Playgroud)
我在尝试将此片段整合到以下示例中时遇到问题,github中的另一个谷歌地图示例,gmaps-samples-v3:
<!DOCTYPE html>
<html>
<head>
<title>Places Search Demo</title>
<link rel="stylesheet" type="text/css"
href="https://google-developers.appspot.com/css/screen.css">
<link rel="stylesheet"
href="https://www.google.com/cse/style/look/default.css" type="text/css">
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places">
</script>
<script type="text/javascript">
var map;
var places;
var iw;
var markers = [];
function initialize() {
var options = {
zoom: 12,
center: new google.maps.LatLng(22.279387,114.164579),
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
};
var mapCanvas = document.getElementById('map_canvas');
map = new google.maps.Map(mapCanvas, …Run Code Online (Sandbox Code Playgroud)