我想搜索我的谷歌地图,但是当我搜索时,附近的搜索功能会返回附近的所有地点。有人知道或有这个问题吗?
谢谢
var map;
function mapsInit() {
var mapNew = document.getElementById('map');
var mapPosition = new google.maps.LatLng(43.509128, 16.457615);
var mapNewOption = {
center: new google.maps.LatLng(43.509128, 16.457615),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(mapNew, mapNewOption);
var marker = new google.maps.Marker({
position: mapPosition,
map: map,
title: "Hotel Dioklecijan"
});
var searchFor = {
location: mapPosition,
radius: 3000,
type: ["stadium"]
};
var service = new google.maps.places.PlacesService(map);
service.nearbySearch(searchFor, function(res, status) {
if (status === "OK"){
for (var i=0; i < res.length; i++){
var marker = new google.maps.Marker({
position: res[i].geometry.location,
map: map,
title: "Hotel Dioklecijan"
});
}
}
});
}
$(document).ready(function(){
mapsInit();
})
您可以在此处查看代码:
https://jsfiddle.net/sghhd59v/6/
答案 0 :(得分:1)
必须是types
,而不是type
var searchFor = { location: mapPosition, radius: 3000, types: ["stadium"] };