我的網頁沒有問題。當我試圖在標記上顯示InfoWindow時。該窗口顯示在地圖的左上角而不是標記上。就像在屏幕下面: InfoWindow在錯誤的地方顯示
這是我用於放置標記和使用InfoWindows的腳本。
var infowindow;
function point(name, lat, long) {
var self = this;
self.name = name;
self.lat = ko.observable(lat);
self.long = ko.observable(long);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, long),
title: name,
map: map,
draggable: true
});
//if you need the poition while dragging
google.maps.event.addListener(marker, 'drag', function() {
var pos = marker.getPosition();
this.lat(pos.lat());
this.long(pos.lng());
}.bind(this));
//if you just need to update it when the user is done dragging
google.maps.event.addListener(marker, 'dragend', function() {
var pos = marker.getPosition();
this.lat(pos.lat());
this.long(pos.lng());
}.bind(this));
google.maps.event.addListener(marker, 'mouseover', function() {
infowindow = new google.maps.InfoWindow({ content: "empty" });
console.log(marker.title);
infowindow.setContent(marker.name);
infowindow.open(map, marker);
}.bind(this));
}
var map = new google.maps.Map(document.getElementById('googleMap'), {
zoom: 5,
center: new google.maps.LatLng(55, 11),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var viewModel = {
points: ko.observableArray([
new point('Test1', 55, 11),
new point('Test2', 56, 12),
new point('Test3', 57, 13)])
};
function addPoint() {
viewModel.points.push(new point('a', 58, 14));
}
ko.applyBindings(viewModel);
這裏所有的的jsfiddle:http://jsfiddle.net/24q8n/
您應提供完整的代碼,如果可能的話的jsfiddle。 – MrUpsidown
已添加! - > http://jsfiddle.net/24q8n/ – szpic
'marker.name'不存在。你正試圖用'setContent'添加它。這會產生錯誤,並將您的infowindow放置在錯誤的地方。使用'marker.title'或者不是'undefined'的東西。 – putvande