Javascript 在“中获取空值”;选择ID(信息ID)";在gmap-v3-geofence.js中

Javascript 在“中获取空值”;选择ID(信息ID)";在gmap-v3-geofence.js中,javascript,google-maps,geofencing,Javascript,Google Maps,Geofencing,gmap-v3-geofence.js:208未捕获类型错误:无法在以下位置将geofence.setInfo(gmap-v3-geofence.js:208)的属性“值”设置为null GeoFerning.js:17处的drawPolygon(GeoFerning.js:27) 我需要一些认真的帮助。我正在使用来自Github的以下代码 我的问题是在谷歌地图上放置一个分区,我也可以拖动该分区并调整其大小,因此我使用以下代码获得了所需的结果: Geofence.prototype.setInf

gmap-v3-geofence.js:208未捕获类型错误:无法在以下位置将geofence.setInfo(gmap-v3-geofence.js:208)的属性“值”设置为null GeoFerning.js:17处的drawPolygon(GeoFerning.js:27)


我需要一些认真的帮助。我正在使用来自Github的以下代码

我的问题是在谷歌地图上放置一个分区,我也可以拖动该分区并调整其大小,因此我使用以下代码获得了所需的结果:

Geofence.prototype.setInfo = function(polygon, infoId) 
{
    selectId(polygon).value = getCoordinatesString(polygon);
}

//本例创建了一个表示百慕大三角形的简单多边形。
//当用户单击多边形时,将打开一个信息窗口,显示
//有关多边形坐标的信息。
var映射;
var信息窗口;
函数initMap(){
map=new google.maps.map(document.getElementById('map'){
缩放:7,
中心:{lat:31.448809299757535,lng:-99.08335389822349},
mapTypeId:'地形'
});
//定义多边形的板条坐标。
var triangleCoords=[
{拉丁美洲:31.4228759492543,液化天然气:-99.89672607421875},
{拉丁美洲:31.03122750234828,液化天然气:-98.66225048828124},
{拉丁美洲:32.0280771432444,液化天然气:-98.65806201171876},
{拉丁美洲:31.735314763657264,液化天然气:-99.22246240234375}
];
//构造多边形。
var bermudaTriangle=新建google.maps.Polygon({
路径:三角形门,
strokeColor:“#FF0000”,
笔划不透明度:0.8,
冲程重量:3,
填充颜色:'#FF0000',
不透明度:0.35,
是的,
真的,
});
百慕大陆角。设定图(map);
//为单击事件添加侦听器。
bermudaTriangle.addListener('click',showArray);
infoWindow=新建google.maps.infoWindow;
}
/**@this{google.maps.Polygon}*/
函数ShowArray(事件){
//因为这个多边形只有一条路径,所以我们可以调用getPath()来返回
//LatLngs的MVCArray。
var顶点=this.getPath();
var contentString='选定多边形
'+ '单击的位置:
'+event.latLng.lat()+','+event.latLng.lng()+ “
”; //在顶点上迭代。 对于(var i=0;i'+xy.lat()+','+ xy.lng(); } //替换信息窗口的内容和位置。 setContent(contentString); infoWindow.setPosition(event.latLng); 打开(地图); }


在此之前,我使用的是geofence-v3-map.js,它已被弃用

你什么时候会收到这个错误?在页面加载时,实际上我想如果我在所选区域内单击,它会给我单击区域的lat,lng。你能发布你的完整代码或JSFIDLE吗?据我所知,演示工作没有问题,谢谢@evan。我已经更改了代码,使用谷歌多边形地图并对其进行更改以满足我的要求。对!我知道你已经自己解决了这个问题?如果是这样,为了社区的利益,请随意回答您自己的问题。如果您仍然存在此问题,请共享您修改的代码,以便我们提供帮助。
<script>
// This example creates a simple polygon representing the Bermuda Triangle.
  // When the user clicks on the polygon an info window opens, showing
  // information about the polygon's coordinates.
  var map;
  var infoWindow;
  function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 7,
      center: {lat: 31.448809299757535, lng: -99.08335389822349},
      mapTypeId: 'terrain'
    });
    // Define the LatLng coordinates for the polygon.
    var triangleCoords = [
        {lat: 31.422875949492543, lng: -99.89672607421875},
        {lat: 31.03122750234828, lng: -98.66225048828124},
        {lat: 32.02807714324144, lng: -98.65806201171876},
        {lat: 31.735314763657264, lng: -99.22246240234375}
    ];
    // Construct the polygon.
    var bermudaTriangle = new google.maps.Polygon({
      paths: triangleCoords,
      strokeColor: '#FF0000',
      strokeOpacity: 0.8,
      strokeWeight: 3,
      fillColor: '#FF0000',
      fillOpacity: 0.35,
      editable: true,
      draggable: true,
    });
    bermudaTriangle.setMap(map);
    // Add a listener for the click event.
    bermudaTriangle.addListener('click', showArrays);
    infoWindow = new google.maps.InfoWindow;
  }
  /** @this {google.maps.Polygon} */
  function showArrays(event) {
    // Since this polygon has only one path, we can call getPath() to return the
    // MVCArray of LatLngs.
    var vertices = this.getPath();
    var contentString = '<b><strong>Selected polygon</strong></b><br>' +
        'Clicked location: <br>' + event.latLng.lat() + ',' + event.latLng.lng() +
        '<br>';
    // Iterate over the vertices.
    for (var i =0; i < vertices.getLength(); i++) {
      var xy = vertices.getAt(i);
      contentString += '<br>' + 'Coordinate ' + i + ':<br>' + xy.lat() + ',' +
          xy.lng();
    }
    // Replace the info window's content and position.
    infoWindow.setContent(contentString);
    infoWindow.setPosition(event.latLng);
    infoWindow.open(map);
  }