Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 谷歌地图点击事件是';t从数据中读取对象_Google Maps_Vue.js_Event Listener - Fatal编程技术网

Google maps 谷歌地图点击事件是';t从数据中读取对象

Google maps 谷歌地图点击事件是';t从数据中读取对象,google-maps,vue.js,event-listener,Google Maps,Vue.js,Event Listener,我试图通过点击地图来获取纬度和经度,然后我使用它们从GoogleMapsAPI获取格式化地址,最后我想在数据中声明的对象“station”中保留lat、lng和格式化地址 data(){ 返回{ 电台:{}, mapName:this.name+“-map”, 拉特:号码, 液化天然气:数量, 完整地址:字符串 }; } , 安装的(){ 常量元素=document.getElementById(this.mapName); 常量选项={ 缩放:14, 中心:新google.maps.La

我试图通过点击地图来获取纬度和经度,然后我使用它们从GoogleMapsAPI获取格式化地址,最后我想在数据中声明的对象“station”中保留lat、lng和格式化地址

data(){
返回{
电台:{},
mapName:this.name+“-map”,
拉特:号码,
液化天然气:数量,
完整地址:字符串
};
}  ,  
安装的(){
常量元素=document.getElementById(this.mapName);
常量选项={
缩放:14,
中心:新google.maps.LatLng(51.501527,-0.1921837)
};
const map=new google.maps.map(元素,选项);
google.maps.event.addListener(映射,“单击”,函数(事件){
this.lat=event.latLng.lat();
this.lng=event.latLng.lng();
axios
.得到(
"https://maps.googleapis.com/maps/api/geocode/json?latlng=" +
这个,拉特+
"," +
这是液化天然气+
“&key=APIKEY”
)
。然后(resp=>{
var完整地址;
console.log(resp.data.results[0]。格式化的\u地址);
fulladdress=resp.data.results[0]。格式化的\u地址;
this.Fulladdress=Fulladdress;
//在我的目标站中保留lat、lng和格式化地址
this.station.address=this.Fulladdress;
this.station.lat=this.lat;
this.station.lng=this.lng;
})
.catch(e=>{
控制台日志(e);
});
});
}

上下文正在更改。在单击处理程序中,
this
不是指Vue实例,而是指其他一些东西(这取决于google maps的操作方式,但它可以是
窗口
或地图实例)

要使
成为Vue实例,请改用箭头函数

更改为:

google.maps.event.addListener(map, "click", function(event) {
致:

google.maps.event.addListener(map, "click", (event)  => {