2009-08-21 64 views
1

代碼谷歌地圖 - 從結果列表中顯示標記窗口

//array store the markers 

var googleMarker = []; 

//this function get json object with the marker data 
//place name,place id,place address. 

function AjaxGetUserToPlaces(res) 
{ 
    var l = res.value.length; 

    for(var i=0;i<l;i++) 
    { 
     var point = new GLatLng(res.value[i].lng,res.value[i].lat) 
     map.addOverlay(createMarkerInfo(i,point,res.value[i].placeName,res.value[i].placeId)); 
     polylineArray.push(point); 
    } 
} 

//the function create the openWindow for the marker. 

function createMarkerInfo(i,latlng , placeName,placeId) 
{ 
    var marker = new GMarker(latlng); 
    marker.value = placeId; 

    GEvent.addListener(marker, 'click', function() 
    { 
    marker.openInfoWindowHtml(''+ 
    '<a href='+baseUrl+'ui/pages/place/place.aspx?plid='+placeId+'>'+placeName+'</a>'); 
     }); 
     googleMarker[i] = marker 

    return marker; 
} 



//this function occur when user click on one of the result. 
//it gets the number in the array googleMarker. 

function showMarkerInfoWindow(i) 
{ 

//here i want to open the marker info window. 
//pay attention, i dont have the html to put inside the infowindow 
//i want just to show the infowindoe with the exising html 
//that created prevusly from the function createMarkerInfo 

    googleMarker[i].openInfoWindowHtml(); 
} 

回答

0

您可以在標記上觸發click事件,打開其信息窗口:

GEvent.trigger(googleMarker[i], googleMarker[i].getLatLng()); 
+0

確定 我嘗試這一點,但它dosent工作 我搜索點點在看房,發現它應該像 GEvent.trigger( googleMarker [i],「點擊」); thanx – avi 2009-08-21 12:50:38

+0

是的,這是我的錯誤,我沒有注意到我正在輸入的內容。高興地指出你在正確的方向! – CalebD 2009-08-21 12:53:51

0

編輯:如果你有座標,可以直接值傳遞給你的createMarker()函數。 像這樣:

HTMLCODE:

<a href="javascript:void(0);" onMouseOver="javascript:createMarker(lat1,lng1,msg1);">List1</a> 
<a href="javascript:void(0);" onMouseOver="javascript:createMarker(lat2,lng2,msg2);">List2</a> 
<a href="javascript:void(0);" onMouseOver="javascript:createMarker(lat3,lng3,msg3);">List3</a> 

JS代碼:

function createMarker(x,y,msg) { 
    var point = new GLatLng(x,y); 
    var myHtml = msg; 
    var baseIcon = new GIcon(); 
    baseIcon.shadow = ""; 
    baseIcon.iconSize = new GSize(20, 34); 
    baseIcon.shadowSize = new GSize(37, 34); 
    baseIcon.iconAnchor = new GPoint(9, 34); 
    baseIcon.infoWindowAnchor = new GPoint(9, 2); 
    baseIcon.infoShadowAnchor = new GPoint(18, 25); 
    var letteredIcon = new GIcon(baseIcon); 
    letteredIcon.image = "http://www.google.com/intl/en_ALL/mapfiles/marker.png"; 
    markerOptions = { icon:letteredIcon }; 
    var marker = new GMarker(point,markerOptions); 
    GEvent.addListener(marker, "mouseover", function() {  
     map.openInfoWindowHtml(point, myHtml); 
    }); 
}