当前的谷歌地图标记位置不正确



我正在使用google-map-mark(在dom-repeat中(与事件:on-google-map-marker-dragend。

我试图在拖动完成后获取标记的当前位置,但我只获取标记的位置,即在当前拖动之前它在拖动上移动的位置。

<google-map zoom="15" id="map" style="height: 20em" api-key="[[apiKey]]" fit-to-markers>
            <template is="dom-repeat" items="[[markers]]" as="mapMarker">
                <google-map-marker on-google-map-marker-click="inform" on-google-map-marker-dragend="inform" click-events="true" draggable="true" drag-events="true" latitude="{{mapMarker.latitude}}" longitude="{{mapMarker.longitude}}">
                </google-map-marker>
            </template>
        </google-map>

方法:

    inform: function(event){
           // this is not the current position after drag end...
           console.log(event.model.mapMarker.latitude);
           console.log(event.target.latitude);
           this.$.userInformationLatitude.innerHTML = event.model.mapMarker.latitude;
           this.$.userInformationLongitude.innerHTML = event.model.mapMarker.longitude;
        }

为了更好地理解,示例:我从纬度:0拖动我的标记经度:0到纽约,拖拽完成后,我得到值纬度:0经度:0,不是纽约的经纬度。

我正在使用观察器来捕获/读取标记位置的变化。

下面是示例 Plunk,元素 my-marker_drag_catch:

   //called on property this.marker_latitude change.          
    marker_latitudeChanged: function() {
      console.log('marker_latitudeChanged');
      if (this.marker_latitude) {
            this.save_marker_data();
      }
    },
    //called on property this.marker_latitude change.          
    marker_longitudeChanged: function() {
      console.log('marker_longitudeChanged');
      if (this.marker_longitude) {
            this.save_marker_data();
      }
    },

我们使用 event.detail.latLng.lat((; 和 event.detail.latLng.lng((; 而不是 event.model...

inform: function(event){
      this.$.userInformationLatitude.innerHTML = event.detail.latLng.lat();
      this.$.userInformationLongitude.innerHTML = event.detail.latLng.lng(); 
}

最新更新