получить значение null в «selectId (infoId)» в gmap-v3-geofence.js - PullRequest
0 голосов
/ 30 сентября 2019
Geofence.prototype.setInfo = function(polygon, infoId) 
{
    selectId(polygon).value = getCoordinatesString(polygon);
}

gmap-v3-geofence.js: 208 Uncaught TypeError: Невозможно установить свойство 'value' для null в Geofence.setInfo (gmap-v3-geofence.js: 208) в drawPolygon (geofencing.js: 27) at geofencing.js: 17

Нужна серьезная помощь. Я использую следующий код от Github. Нажмите здесь

1 Ответ

0 голосов
/ 03 октября 2019

Моя проблема заключалась в том, чтобы поместить на карту Google раздел, который я также могу перетащить и изменить его размер, поэтому я использовал следующий код и получил требуемый результат:

<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);
  }

До этого я использовал geofence-v3-map.js, который устарел.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...