0
我從API獲取一些信息。 我打電話給地理編碼器以獲取該點,然後創建我的標記,併爲信息窗口顯示一些文本。 我的標記放在地圖上沒有問題。Proplem與谷歌地圖infowindow
但是當我點擊該標記時,它總是顯示相同的文本。 我無法弄清楚如何「預填充」的信息窗口,所以當我點擊標記它顯示了正確的信息......
function createMarker(point, text) {
alert('point: ' + point + 'text: ' + text)
var html ="<div class='infowindow'><strong>"+ text + "<\/strong><\/div>";
//var marker = new GMarker(point, markerOptions);
var marker = new google.maps.Marker({
map: map,
position: point
});
infowindow = new google.maps.InfoWindow({
content: html
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
return marker;
}
我希望這是很清楚! 我使用谷歌API V3
使用下面的代碼解決它:
function createMarker(point, text) {
//var html ="<div class='infowindow'><strong>"+ text + "<\/strong><\/div>";
//var marker = new google.maps.Marker({
// map: map,
// position: point
//});
//infowindow = new google.maps.InfoWindow({
// content: html
//});
//google.maps.event.addListener(marker, 'click', function() {
// infowindow.open(map, marker);
//});
//return marker;
var title = 'LinkedIn Connection';
var html = "<div class='infowindow'><strong>"+ text + "<\/strong><\/div>";
var marker = new google.maps.Marker({
title:title,
content:html,
map:map,
draggable:false,
position:point
});
google.maps.event.addListener(marker, 'click', function() {
/* close the previous info-window */
closeInfos();
/* the marker's content gets attached to the info-window: */
var info = new google.maps.InfoWindow({content: this.content});
/* trigger the infobox's open function */
info.open(map,this);
/* keep the handle, in order to close it on next click event */
infos[0]=info;
});
}
function closeInfos(){
if(infos.length > 0){
/* detach the info-window from the marker */
infos[0].set("marker",null);
/* and close it */
infos[0].close();
/* blank the array */
infos.length = 0;
}}
您可以檢查結果這裏:www.pukkafish.com/api/linkedin。您將需要一個linkedIn帳戶。 – Olivier 2012-02-01 08:51:51