2017-08-18 20 views
3

私はreact-google-mapsパッケージhttps://github.com/tomchentw/react-google-mapshttps://www.npmjs.com/package/react-google-mapsを使って作業しています。エラーでリアクションGoogleマップは反応しません

./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 

とHERESに私のラインを::

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

すべての「グーグル事がエラーである私が言うエラーが発生しています。

答えて

4

答えは、私は私のファイルの先頭に次の行/* global google */が含まdidntのです。

+0

詳細な回答をお願いできますか? – neelima

+1

このエラーはEslintによって発生しました。あなたはファイルの先頭に/ * global google * /を追加してESLintを無効にすることができます。 – Deee

3

googleが定義されていない場合は、Google Maps APIを正しく読み込みませんでした。 react-google-maps's READMEで説明したように、あなたは、コンポーネントのコードのロードに反応前に、あなたのHTML でこれを置く:

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_GOOGLE_MAPS_API_KEY_GOES_HERE"></script> 
+0

を行う設定ファイル、エラーを解決するために、ウィンドウの参照を含めることができます。 – neelima

1

あなたはまた、単に、少なくともデフォルトで作成反応するアプリは、それは私はまだグーグル未定義、スクリプトが含まれている

new window.google.maps.LatLng(41.8507300, -87.6512600) 
関連する問題