问题陈述
radarSearch仅在初始加载时返回靠近地图中心的位置,并且仅返回大约140(而不是200)。我将请求对象的bounds成员设置为map.getBounds ... 当我移动地图的中心时,会添加更多地点......
的问题
为什么我得到的广告超过200个广告位?我如何获得地图区域的详尽搜索结果?
代码
HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<style type="text/css">
html, body, #map-canvas {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="JavaScriptMin.js"></script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
的Javascript
var map;
var infoWindow;
var service;
function initialize() {
var mapOptions = {
zoom: 5,
center: new google.maps.LatLng(-27.984113, 153.411076)
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
google.maps.event.addListener(map, 'bounds_changed', performSearch);
}
function loadScript() {
var script = document.createElement('script'),
myScript = 'https://maps.googleapis.com/maps/api/js?signed_in=true&v=2.exp' +
'&libraries=weather,places&sensor;=true_or_false&signed_in=true&callback=initialize®ion=au'
script.type = 'text/javascript';
script.src = myScript;
document.body.appendChild(script);
}
window.onload = loadScript;
function performSearch() {
var request = {
bounds: map.getBounds(),
keyword: 'caravan parks'
};
if (!infoWindow) { infoWindow = new google.maps.InfoWindow() };
if (!service) { service = new google.maps.places.PlacesService(map) };
service.radarSearch(request, searchCallback);
}
function searchCallback(results, status, pagination) {
if (results) { console.log('searchCallback, results count is ' + results.length) };
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
createMarker(results[i]);
}
} else {
console.log('search failed')
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 2,
opacity: 1,
fillColor: 'red',
fillOpacity: 1,
strokeColor: 'red',
strokeWeight: 1
},
position: place.geometry.location
});
}
注意:
答案 0 :(得分:1)
我最终成功地自己解决了这个问题,我的发现如下......