1
我在我的Rails應用程序中使用Google Maps,我面臨一些困難。 我想在用戶點擊一個圓圈時顯示一個infowindow。當他點擊一個標記時,它工作正常,但現在我有圈不起作用。Google Map infowindow不開放
這裏是我的代碼:
markers_json = <%= raw @circles %>;
var map;
var infoWindow;
buildMap = function(){
var mapStyle = [
// https://snazzymaps.com/style/70/unsaturated-browns
{"elementType":"geometry","stylers":[{"hue":"#ff4400"},{"saturation":-68},{"lightness":-4},{"gamma":0.72}]},{"featureType":"road","elementType":"labels.icon"},{"featureType":"landscape.man_made","elementType":"geometry","stylers":[{"hue":"#0077ff"},{"gamma":3.1}]},{"featureType":"water","stylers":[{"hue":"#00ccff"},{"gamma":0.44},{"saturation":-33}]},{"featureType":"poi.park","stylers":[{"hue":"#44ff00"},{"saturation":-23}]},{"featureType":"water","elementType":"labels.text.fill","stylers":[{"hue":"#007fff"},{"gamma":0.77},{"saturation":65},{"lightness":99}]},{"featureType":"water","elementType":"labels.text.stroke","stylers":[{"gamma":0.11},{"weight":5.6},{"saturation":99},{"hue":"#0091ff"},{"lightness":-86}]},{"featureType":"transit.line","elementType":"geometry","stylers":[{"lightness":-48},{"hue":"#ff5e00"},{"gamma":1.2},{"saturation":-23}]},{"featureType":"transit","elementType":"labels.text.stroke","stylers":[{"saturation":-64},{"hue":"#ff9100"},{"lightness":16},{"gamma":0.47},{"weight":2.7}]}
];
handler = Gmaps.build('Google');
map = handler.buildMap({
internal: {id: 'map'},
provider: {
//disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: mapStyle,
scrollwheel: false
}
}, function(){
var circles = handler.addCircles(markers_json, {strokeWeight: 1, strokeColor: '#aaa'});
handler.bounds.extendWith(circles);
handler.fitMapToBounds();
for (var i = 0; i < circles.length; ++i) {
var marker = circles[i];
//google.maps.event.addListener(marker.serviceObject, 'click', onMarkerClick(marker));
addInfoWindow(marker, 'hey');
}
});
};
function addInfoWindow(marker, content) {
var infoWindow = new google.maps.InfoWindow({
content: content
});
google.maps.event.addListener(marker.serviceObject, 'click', function() {
i = infoWindow.open(map, marker.serviceObject);
console.log(i);
});
}
我一次又一次地有這樣的錯誤,當我嘗試打開信息窗口: Uncaught TypeError: Cannot read property 'get' of undefined(…)
所以我試圖做i = infoWindow.open(map.serviceObject, marker.serviceObject);
但現在什麼也沒有發生,我甚至沒有錯誤信息。
我真的不知道我還能做什麼...你能幫我嗎?