我正在尝试从用户获取地名并在初始地图加载时在Google地图上标记。所以我所做的是使用来自另一个页面的会话获取地名和缩放值,并将其放在地图属性中。缩放部分工作正常,但标记部分不起作用,我已经研究了很多并尝试了不同的东西,但这是我最新版本的代码,它在地图上没有显示标记,并且没有错误好。
这是我的代码:
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
var myStyles =[
{
featureType: "poi",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
}
];
function initialize() {
var zm = <%= Session["value2"]%>;
var ft= '<%= Request.QueryString["value"] %>';
navigator.geolocation.getCurrentPosition(function (position) {
var latlng2 = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map = new google.maps.Map(document.getElementById('map'), {
center: latlng2,
zoom: zm,
styles: myStyles
});
var request2 = {
location: latlng2,
radius: 2000,
types: [ft]
};
service.nearbySearch(request2, callback);
});
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i],icon);
}
}
}
function createMarker(place,icon) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
icon: icon,
visible:true
});
markersArray.push(marker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent("<b>Name:</b>"+place.name+"<br><b>Address:</b>"+place.vicinity);
infowindow.open(map, this);
});
}
如果你帮助我,我会非常感激。
答案 0 :(得分:1)
TypeError: service.nearbysearch is not a function
根据nearbySearch
nearbysearch
而不是GOOGLE MAPS API DOCUMENTAION