2017-10-19 75 views
-1

我正在使用谷歌地圖與反應。但是,當我跑我的項目,我得到了Polygon.js錯誤文件谷歌地圖與ReactJs

TypeError: Cannot read property 'Component' of undefined

TypeError: Cannot read property 'array' of undefined

請讓我知道爲什麼嗎?

這是剪斷代碼和圖片描述錯誤:

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import PropTypes from 'prop-types' 
import { GoogleAPIWrapper, InfoWindow, Marker } from 'google-maps-react' 


export class MapContainer extends React.Component { 

    componentDidMount() { 
    this.loadMap(); 
    } 
    loadMap() { 
    let map = new window.google.maps.Map(document.getElementById('map'), { 
     center: { lat: -33.8688, lng: 151.2195 }, 
     zoom: 13, 
     mapTypeID: 'roadmap' 
    }) 
    } 

    render() { 
    const style = { 
     width: "100%", 
     hight: "100%" 
    }; 
    return (
     <div id='map'> 
     </div> 
    ); 
    } 
} 
export default GoogleAPIWrapper(
    { 
    apiKey: "MY_KEY", 
    } 
)(MapContainer); 

Error_1

Error_2

+1

是吧'GoogleAPIWarapper'或'GoogleAPIWrapper'? AND不是你在構造函數中綁定'loadMap()'嗎? – Dane

+0

嗨丹尼! Sr,我是GoogleAPIWarapper(GoogleAPIWrapper)中的錯誤類型。我已經得到新的錯誤「類型錯誤:對象(...)不是一個函數」在行:出口默認GoogleAPIWrapper( { apiKey:「MY_KEY」 } )(MapContainer); – Foxes

回答

1

看來你在代碼中有一些錯誤, 繼docs,你不應該甚至能夠導出你的組件(在'GoogleAPIWarapper'中輸入錯字)。

工作示例

import {Map, InfoWindow, Marker, GoogleApiWrapper} from 'google-maps-react'; 
import React, { Component} from 'react'; 
export class MapContainer extends Component { 
render() { 
    return (
    <Map google={this.props.google} zoom={14}> 
     <Marker onClick={this.onMarkerClick} 
      name={'Current location'} /> 
     <InfoWindow onClose={this.onInfoWindowClose}> 
     <div> 
     <h1>Test</h1> 
     </div> 
     </InfoWindow> 
    </Map> 
); 
} 
} 
export default GoogleApiWrapper({ 
    apiKey: 'apiKey' 
})(MapContainer) 
+0

Tks。我的項目工作,這是我的錯。因爲我不明白它的活動方式。 – Foxes