Reactjs react-google-maps未定义 [英] Reactjs react-google-maps undefined

查看:118
本文介绍了Reactjs react-google-maps未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用react-google-maps软件包 https://github.com/ tomchentw / react-google-maps https://www.npmjs。 COM /包/反应-谷歌-地图。我有一个错误提示:

I am working with the react-google-maps package https://github.com/tomchentw/react-google-maps and https://www.npmjs.com/package/react-google-maps. I have an error that says:

./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}`);
        }
    });
}

所有'google'的东西都是错误的。

all the 'google' thing is error.

推荐答案

答案是我没有包含这行 / * global google * / 到我的文件顶部。

the answer is I didnt include this line /* global google */ to the top of my file.

这篇关于Reactjs react-google-maps未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆