我想让德国城市的餐馆在网页中嵌入和处理。我通过纬度/经度和半径(近似值)识别这些城市。
在Google地图上进行在线搜索时,我会看到100个结果。
google maps restaurant search duesseldorf
我尝试实现(主要基于此处的示例)只会返回少得多的结果(您可以复制到.html页面)。我也尝试添加API密钥,我在这里删除了。
(我认为在哪里说"请求"对搜索结果很有意思。)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
padding: 0;
}
#map_canvas {
height: 100%;
}
#search-panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
width: 350px;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
}
#target {
width: 345px;
}
</style>
<script type="text/javascript">
var aDone = false;
var bDone = false;
function initializea() {
aDone = true;
if (aDone && bDone)
initialize();
}
function initializeb() {
bDone = true;
if (aDone && bDone)
initialize();
}
function initialize() {
{
// cologne
var plat = 50.9344595;
var plong = 6.9476285;
// duesseldorf
plat = 51.2277411;
plong = 6.7734556;
var ppos = new google.maps.LatLng(plat, plong);
var mapOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
//draggable: false,
zoom: 13,
center: ppos
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var request = {
location: ppos,
radius: 4000,
//keyword: 'restaurant+food',
type: 'food'
// key: 'MY_API_KEY makes no difference'
};
infowindow = new google.maps.InfoWindow();
service = new google.maps.places.PlacesService(map);
service.search(request, callback);
};
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
icon: place.icon
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent("<b>" + place.name + "</b><br/>" + place.vicinity);
infowindow.open(map, this);
});
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&callback=initializea";
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
</head>
<body onload="initializeb()">
<div id="search-panel">
<input id="target" type="text" placeholder="Search Box">
</div>
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
我还尝试使用餐厅和食物来改变类型/关键字。结果不会变得更好或更频繁。
如何获得更多结果?
(我想给用户一个合理的选择吃饭的地方,而不仅仅是4个城市的50万人(以及100多家餐馆,谷歌也知道并返回地图搜索)。)
类似的问题(没有有用的答案):
Why do some results show up in Google Maps but not in Places API results?
Different results in Google Places API and Google Maps
Different results in Google Places API and Google Maps
https://stackoverflow.com/questions/21230939/places-api-returning-fewer-results
答案 0 :(得分:1)
基本上:不关心maps.google.com,当您使用与API相关的maps-API时,几乎所有内容都会记录在案,并且文档永远不会保证返回所有内容。
您运行nearbySearch
,最多返回20个(分页60)结果,您无法通过附近的搜索获得更多结果。
您可以运行radarSearch
,而最多可返回200个结果(但细节较少)