如何从 info window 中删除信息(在 KmlLayer 上)

How to remove information from info window (on a KmlLayer)

我正在使用 Google 地图 API 并且我已经将 kml 图层导入到我的 code.My 问题是我不知道如何删除 'Unknown Point Feature'信息来自信息window。有什么建议么?这是我正在谈论的内容的屏幕截图:

这是我导入 kml 文件的代码:

var AI_url = 'https://drive.google.com/uc?export=download&id=0B2KR4Lz3foYEeEtfR0laWWM0LVk'            
var AI_options = {
    preserveViewport: true,
    map: map
};
var AI_layer = new google.maps.KmlLayer(AI_url, AI_options);

信息 window 内容来自 KML 文件,因此您必须从那里删除它,前提是您当然可以从提供文件的位置访问该文件。

来自API: https://developers.google.com/maps/tutorials/kml/

var kmlOptions = {
  **suppressInfoWindows: true,**
  preserveViewport: false,
  map: map
};

一个选项是设置 KmlLayer 的 suppressInfoWindows 选项,然后添加您自己的仅显示 "name":

的点击侦听器
var AI_url = 'https://drive.google.com/uc?export=download&id=0B2KR4Lz3foYEeEtfR0laWWM0LVk'
var AI_options = {
    preserveViewport: true,
    suppressInfoWindows: true,
    map: map
};
var AI_layer = new google.maps.KmlLayer(AI_url, AI_options);
google.maps.event.addListener(AI_layer,'click',function(e) {
    infoWindow.setOptions({
      content:"<b>"+e.featureData.name+"</b>",
      pixelOffset:e.pixelOffset, 
      position:e.latLng
    });
    infoWindow.open(map);
});

概念验证代码片段:

var geocoder;
var map;
var infoWindow = new google.maps.InfoWindow();

function initialize() {
  geocoder = new google.maps.Geocoder();
  map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

  var AI_url = 'https://drive.google.com/uc?export=download&id=0B2KR4Lz3foYEeEtfR0laWWM0LVk'
  var AI_options = {
    preserveViewport: true,
    suppressInfoWindows: true,
    map: map
  };
  var AI_layer = new google.maps.KmlLayer(AI_url, AI_options);
  google.maps.event.addListener(AI_layer, 'click', function(e) {
    infoWindow.setOptions({
      content: "<b>" + e.featureData.name + "</b>",
      pixelOffset: e.pixelOffset,
      position: e.latLng
    });
    infoWindow.open(map);
  });

  codeAddress("Calgary, Canada");

}
google.maps.event.addDomListener(window, "load", initialize);

function codeAddress(address) {
  geocoder.geocode({
    'address': address
  }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.fitBounds(results[0].geometry.viewport);
    } else {
      alert("Geocode was not successful for the following reason: " + status);
    }
  });
}
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas" style="border: 2px solid #3872ac;"></div>