在componentDidUpdate中初始化地图控件,地图能够显示,点击地图中的点时能正确获取经纬度,但是控制台会不断的报错。
代码如下:
initMap(){
console.log("initMap===================");
let moduleProps = this.state.moduleProps;
var map = new AMap.Map("ma-container", {
resizeEnable: true,
center: [moduleProps.longitude,moduleProps.latitude],//地图中心点
zoom: 13 //地图显示的缩放级别
});
var marker = new AMap.Marker({
icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
position: [moduleProps.longitude,moduleProps.latitude]
});
marker.setMap(map);
//为地图注册click事件获取鼠标点击出的经纬度坐标
var clickEventListener = map.on('click', (e)=> {
moduleProps.longitude=e.lnglat.getLng();
moduleProps.latitude=e.lnglat.getLat();
console.log("aaaa====" + this.state.moduleProps.longitude);
this.setState({moduleProps: moduleProps}, ()=> {
console.log("hahah====" + this.state.moduleProps.longitude);
});
});
}
报错的是216行

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
解决了,修改了一下结构。