Google Maps Marker Selection

问题描述

| 问候, 我正在使用来自PHP函数的xml在Google Maps上动态加载标记 另外,我使用该XML来构建包含所有位置的表。 问题是如何将每个表条目链接一个标记,以便我可以单击该位置,并且该标记出现在地图的中心并打开信息窗口?     

解决方法

        创建标记对象时,请为其提供一个ID:
var alatlng = new google.maps.LatLng(lat,lon);
var marker = new google.maps.Marker({
    position: alatlng,title:\"Hello World!\",icon: image
});

marker.setValues({type: \"point\",id: counter });
marker.setMap(map);
然后,您可以使用addDomListener将侦听器添加到表对象的点击事件(超链接等)
google.maps.event.addDomListener(document.getElementById(\"result\" + counter),\'click\',function() {
    map.setCenter( latlngbounds.getCenter( ) );
});
使用以下方法设置地图的范围:
var latlngbounds = new google.maps.LatLngBounds( );
latlngbounds.extend(alatlng);
并非100%肯定您的帖子是您想要的,但是它应该为您拼凑而成。