谷歌地图API标记 - 鼠标悬停而非点击 - 使用kml

时间:2011-11-01 09:29:55

标签: google-maps google-maps-api-3 kml mouseover marker

我想从kml文件中获取标记并在地图上显示它们,但是为工具提示添加“mouseover”,而不是单击

使用此代码,但它不起作用(如果我使用点击则有效)

function initialize() {
    var latlng = new google.maps.LatLng(53.477876, -2.471289);
    var myOptions = {
      zoom: 5,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    //kml begin
    var nyLayer = new google.maps.KmlLayer('http://code.nebtron.com/kml2.kml', {suppressInfoWindows: false});
    nyLayer.setMap(map);
    google.maps.event.addListener(nyLayer, "mouseover", function(kmlEvent) {
      var text = kmlEvent.featureData.description;
      showInDiv(text);
    });

    function showInDiv(text) {
      var sidediv = document.getElementById('contentWindow');
      sidediv.innerHTML = text;
    }//kml end

  }

演示:http://code.nebtron.com/map3.php

1 个答案:

答案 0 :(得分:1)

正如here所指出,mouseover没有KMLLayers个事件。但也许你可以使用polygon。这是一个link

希望这有帮助!