我是角色新手,我有一个包含两个字段 source 和 destination 的表单。这些字段使用google maps api从地图标记中获取其值。设置标记位置时,第一个输入的值会快速更新,但第二个输入(目的地)会在模糊事件中获得其值(在我点击它并点击外部之后)。
组件中的部分代码:
locateSource(){
this.mapCenter = this.map.getCenter();
this.markerSource.setPosition(this.mapCenter);
this.sourceLat = this.markerSource.getPosition().lat();
this.sourceLng = this.markerSource.getPosition().lng();
this._orderService.getPlaceName(this.sourceLat, this.sourceLng).subscribe(
name => {
this.sourceAddress = name;
}
);
}
locateDestination(){
this.mapCenter = this.map.getCenter();
this.markerDestination.setPosition(this.mapCenter);
this.destinationLat = this.markerDestination.getPosition().lat();
this.destinationLng = this.markerDestination.getPosition().lng();
this._orderService.getPlaceName(this.destinationLat, this.destinationLng).subscribe(
name => {
this.destinationAddress = name;
}
);
}
是什么原因?
答案 0 :(得分:1)
在实施google maps api时,我也遇到过类似的问题。虽然,我通过添加
来修复(或者我必须说修补)document.body.click().
它与角度无法检测到变化有关,因为你调用地图api,控件与角度分离,因此它无法找出变化。
虽然我的修复是一种hacky方式,但它有效,我很乐意看看是否有人有适当的修复