gpt4 book ai didi

javascript - Reactjs react 谷歌地图未定义

转载 作者:数据小太阳 更新时间:2023-10-29 05:53:54 26 4
gpt4 key购买 nike

我正在使用 react-google-maps 包 https://github.com/tomchentw/react-google-mapshttps://www.npmjs.com/package/react-google-maps .我有一条错误消息:

./src/App.js Line 31:  'google' is not defined  no-undef  Line 32:  'google' is not defined  no-undef  Line 37:  'google' is not defined  no-undef Line 42:  'google' is not defined  no-undef Line 44:  'google' is not defined  no-undef

这是我在错误中的行:

 state = {
origin: new google.maps.LatLng(41.8507300, -87.6512600),
destination: new google.maps.LatLng(41.8525800, -87.6514100),
directions: null,
}

componentDidMount() {
const DirectionsService = new google.maps.DirectionsService();

DirectionsService.route({
origin: this.state.origin,
destination: this.state.destination,
travelMode: google.maps.TravelMode.DRIVING,
}, (result, status) => {
if (status === google.maps.DirectionsStatus.OK) {
this.setState({
directions: result,
});
} else {
console.error(`error fetching directions ${result}`);
}
});
}

所有“谷歌”的东西都是错误的。

最佳答案

答案是我没有将此行 /* global google */ 包含在我的文件顶部。

关于javascript - Reactjs react 谷歌地图未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45747496/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com