2009-08-21 66 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); 
    }); 
}