Google maps api 3 定制信息盒

Google maps api 3 定制信息盒,google-maps-api-3,infowindow,Google Maps Api 3,Infowindow,我已经设法在我的一个地图上实现了“信息框”,该地图加载mySQL数据库中保存的位置,但我想对此做一些更改,但我不确定如何更改 我正在使用的代码如下所示,但我希望能够替换信息框的“默认”行为,即在地图加载时出现在每个标记旁边,信息框仅在单击标记后出现,平移以将地图置于该标记的中心。然后,单击下一个标记时,信息框将从第一个标记移动到新单击的标记,再次具有平移和居中功能 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http:

我已经设法在我的一个地图上实现了“信息框”,该地图加载mySQL数据库中保存的位置,但我想对此做一些更改,但我不确定如何更改

我正在使用的代码如下所示,但我希望能够替换信息框的“默认”行为,即在地图加载时出现在每个标记旁边,信息框仅在单击标记后出现,平移以将地图置于该标记的中心。然后,单击下一个标记时,信息框将从第一个标记移动到新单击的标记,再次具有平移和居中功能

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Map My Finds - All Locations</title>
        <link rel="stylesheet" href="css/alllocationsstyle.css" type="text/css" media="all" />
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
        <script type="text/javascript" src="js/infobox.js"></script>
        <script type="text/javascript"> 
            var customIcons = {
            0: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
            shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
            },
            1: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_green.png',
            shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
            }
            };

            function load() { 
            var map = new google.maps.Map(document.getElementById("map"), { 
            center: new google.maps.LatLng(54.312195845815246,-4.45948481875007), 
            zoom:6, 
            mapTypeId: 'roadmap' 
            }); 

            // Change this depending on the name of your PHP file 
            downloadUrl("loadalllocations.php", function(data) { 
            var xml = data.responseXML; 
            var markers = xml.documentElement.getElementsByTagName("marker");
            var bounds = new google.maps.LatLngBounds();
            for (var i = 0; i < markers.length; i++) { 
            var locationname = markers[i].getAttribute("locationname"); 
            var address = markers[i].getAttribute("address");
            var totalfinds = markers[i].getAttribute("totalfinds");
            var point = new google.maps.LatLng( 
            parseFloat(markers[i].getAttribute("osgb36lat")), 
            parseFloat(markers[i].getAttribute("osgb36lon")));
            var icon = {}; 
            if (totalfinds == 0) {   
            icon = customIcons[0]; 
            } else if (totalfinds >= 1) {   
            icon = customIcons[1];      
            } 
            var marker = new google.maps.Marker({          
            map: map, 
            position: point,
            title: address,
            icon: icon.icon,
            shadow: icon.shadow
            }); 
            bounds.extend(point);
            map.fitBounds(bounds);

            var boxText = document.createElement("div");
            boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: orange; padding: 5px;";
            boxText.innerHTML = locationname + "<p>" + 'No. of finds: ' + "<b>" + totalfinds + "</b>" + "</p>";;
            var myOptions = {
            content: boxText
            ,disableAutoPan: false
            ,maxWidth: 0
            ,pixelOffset: new google.maps.Size(-140, 0)
            ,zIndex: null
            ,boxStyle: { 
            background: "url('tipbox.gif') no-repeat"
            ,opacity: 0.50
            ,width: "180px"
            }
            ,closeBoxMargin: "10px 2px 2px 2px"
            ,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
            ,infoBoxClearance: new google.maps.Size(1, 1)
            ,isHidden: false
            ,pane: "floatPane"
            ,enableEventPropagation: false
            };
            var ib = new InfoBox(myOptions);
            ib.open(map, marker);

            } 
            }); 
            } 

            function downloadUrl(url, callback) { 
            var request = window.ActiveXObject ? 
            new ActiveXObject('Microsoft.XMLHTTP') : 
            new XMLHttpRequest; 

            request.onreadystatechange = function() { 
            if (request.readyState == 4) { 
            request.onreadystatechange = doNothing; 
            callback(request, request.status); 
            } 
            }; 

            request.open('GET', url, true); 
            request.send(null); 
            } 

            function doNothing() {} 

            </script> 
            </head>    
            <body onLoad="load()">
                <div id="map"></div>
            </body> 
            </html>

映射我的发现-所有位置
var customIcons={
0: {
图标:'http://labs.google.com/ridefinder/images/mm_20_red.png',
影子:'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
1: {
图标:'http://labs.google.com/ridefinder/images/mm_20_green.png',
影子:'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
函数加载(){
var map=new google.maps.map(document.getElementById(“map”),{
中心:新google.maps.LatLng(54.312195845845815246,-4.45948481875007),
缩放:6,
mapTypeId:“路线图”
}); 
//根据PHP文件的名称更改此选项
下载URL(“loadalllocations.php”,函数(数据){
var xml=data.responseXML;
var markers=xml.documentElement.getElementsByTagName(“标记”);
var bounds=new google.maps.LatLngBounds();
对于(var i=0;i=1){
图标=自定义图标[1];
} 
var marker=new google.maps.marker({
地图:地图,
位置:点,,
标题:地址,
icon:icon.icon,
阴影:icon.shadow
}); 
扩展(点);
映射边界(bounds);
var-boxText=document.createElement(“div”);
boxText.style.cssText=“边框:1px纯黑色;页边距顶部:8px;背景:橙色;填充:5px;”;
boxText.innerHTML=locationname+“”+”查找数:“+”+totalfinds+“+”

”;; 变量myOptions={ 内容:boxText ,disableAutoPan:false ,最大宽度:0 ,pixelOffset:new google.maps.Size(-140,0) ,zIndex:null ,boxStyle:{ 背景:“url('tipbox.gif')不重复” ,不透明度:0.50 ,宽度:“180像素” } ,closeBoxMargin:“10px 2px 2px 2px” ,closeBoxURL:“http://www.google.com/intl/en_us/mapfiles/close.gif" ,infoBoxClearance:newgoogle.maps.Size(1,1) ,isHidden:错 ,窗格:“浮动窗格” ,enableEventPropagation:false }; var ib=新信息框(myOptions); ib.open(地图、标记); } }); } 函数下载url(url,回调){ var请求=window.ActiveXObject? 新的ActiveXObject('Microsoft.XMLHTTP'): 新的XMLHttpRequest; request.onreadystatechange=函数(){ 如果(request.readyState==4){ request.onreadystatechange=doNothing; 回调(请求、请求、状态); } }; 打开('GET',url,true); 请求发送(空); } 函数doNothing(){}
我还想了解更多关于信息框的信息,比如改变颜色、边距等,但我只发现指南并不像我希望的那样详细。还有别的地方可以让我得到更详细的信息吗


此问题现已解决,代码正在运行。

尝试此方法

有一个

你可能正在寻找的细节是

var contentString = '<div id="content">'+
    '<div id="siteNotice">'+
    '</div>'+
    '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
    '<div id="bodyContent">'+
    '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
    'sandstone rock formation in the southern part of the '+
    'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
    'south west of the nearest large town, Alice Springs; 450&#160;km '+
    '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+
    'features of the Uluru - Kata Tjuta National Park. Uluru is '+
    'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
    'Aboriginal people of the area. It has many springs, waterholes, '+
    'rock caves and ancient paintings. Uluru is listed as a World '+
    'Heritage Site.</p>'+
    '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
    'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
    '(last visited June 22, 2009).</p>'+
    '</div>'+
    '</div>';

//create info window with a specific content string
var infowindow = new google.maps.InfoWindow({
    content: contentString
});

//marker listener
google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,marker);
});
var contentString=''+
''+
''+
“乌鲁鲁”+
''+
“Uluru,也称为艾尔斯岩,是一个大型的”+
“南部的砂岩岩层”+
“北领地,澳大利亚中部。它位于335和160之间;公里(208英里)+
“最近的大城镇爱丽丝·斯普林斯西南部;450 公里+
"(280和160英里)的公路。Kata Tjuta和Uluru是两个主要的+
“乌鲁鲁-卡塔朱塔国家公园的特色。乌卢鲁是+
“对Pitjantjatjara和Yankunytjatjara来说是神圣的”+
“该地区的土著居民。它有许多泉水、水坑+
“岩洞和古画。乌卢鲁被列为世界上最大的城市+
“遗产地。

”+ “归属:乌卢鲁,”+ (上次访问日期为2009年6月22日)。

'+ ''+ ''; //使用特定内容字符串创建信息窗口 var infowindow=new google.maps.infowindow({ 内容:contentString }); //标记侦听器 google.maps.event.addListener(标记'click',函数(){ 信息窗口。打开(地图、标记); });
试试这个

有一个

你可能正在寻找的细节是

var contentString = '<div id="content">'+
    '<div id="siteNotice">'+
    '</div>'+
    '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
    '<div id="bodyContent">'+
    '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
    'sandstone rock formation in the southern part of the '+
    'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
    'south west of the nearest large town, Alice Springs; 450&#160;km '+
    '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+
    'features of the Uluru - Kata Tjuta National Park. Uluru is '+
    'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
    'Aboriginal people of the area. It has many springs, waterholes, '+
    'rock caves and ancient paintings. Uluru is listed as a World '+
    'Heritage Site.</p>'+
    '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
    'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
    '(last visited June 22, 2009).</p>'+
    '</div>'+
    '</div>';

//create info window with a specific content string
var infowindow = new google.maps.InfoWindow({
    content: contentString
});

//marker listener
google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,marker);
});
var contentString=''+
''+
''+
“乌鲁鲁”+
''+
“乌卢鲁,也是