0

我的谷歌地图工作正常,但鼠标悬停和鼠标悬停没有显示 div。谁能看到我的错误或我做错了什么?我的主机服务器上安装了 jquery。

<html>
<head>
<title>Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">

<script src="jquery/jquery.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

<script type="text/javascript">
function initialize() {
    var LatLng = new google.maps.LatLng(51.620946, -8.890981);
    var mapOptions = {
        zoom: 12,
        center: LatLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

    var contentstring = '<div style="height:50px;background-color:red;width:50px;">Hello</div>';           

    var LatLng = new google.maps.LatLng(51.620946, -8.890981);
    var marker_0 = new google.maps.Marker({
        position:LatLng,
    map:map,
    descrip:contentstring,
    link:'https://www.google.ie/'
    }) 

    google.maps.event.addListener(marker_0,'mouseover',function(){
    tooltip.show(this.descrip); 
    });

    google.maps.event.addListener(marker_0,'mouseout',function(){
        tooltip.hide(); 
    });

    google.maps.event.addListener(marker_0,'click',function(){
        window.open(this.link);     
    }); 
}

$(document).ready(function(){
    initialize();
})



</script>
</head>
<body>
    <div id="map-canvas" style="width:600px;height:400px;border:solid 1px red;"></div>
</body> 
</html> 

提前感谢您的帮助。

4

2 回答 2

0

从上面的代码看,您似乎没有定义变量“工具提示”

于 2013-07-04T23:38:07.847 回答
0

不要将descripandlink属性传递给 your marker_0,而是尝试传递 thetitle并且它可以工作。像这样...

function initialize() {
    var LatLng = new google.maps.LatLng(51.620946, -8.890981);
    var mapOptions = {
        zoom: 12,
        center: LatLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    var contentstring = '<div style="height:50px;background-color:red;width:50px;">Hello</div>';           

    var marker_0 = new google.maps.Marker({
        position:LatLng,
        map:map,
        title: contentstring
        //descrip:contentstring,
        //link:'https://www.google.ie/'
    }) 

    /*

    ** HAVE COMMENTED THIS BIT OUT AS THE MARKER ABOVE WILL WORK AS A TOOL TIP **
    google.maps.event.addListener(marker_0,'mouseover',function(){
        tooltip.show(this.descrip); 
    });

    google.maps.event.addListener(marker_0,'mouseout',function(){
        tooltip.hide(); 
    });

    google.maps.event.addListener(marker_0,'click',function(){
        window.open(this.link);     
    }); */
}

这里有一个简单的标记示例

可用于标记的属性在DOCS中列出。

希望这可以帮助。

于 2013-07-05T00:34:00.280 回答