Google map for meteor

☆樱花仙子☆ 提交于 2019-12-11 06:20:09

问题


I install "meteor add dburles:google-maps" in Meteor. I added this code to the React Component,

...
import { GoogleMaps } from 'meteor/dburles:google-maps';
...
export default class Location extends TrackerReact(React.Component){
constructor(props) {
    super(props);
    this.state = {
        ...
    };
    GoogleMaps.load();
}
componentDidUpdate(){
    GoogleMaps.create({
      name: 'exampleMap',
      element: document.getElementById('basic_map'),
      options: {
        center: new google.maps.LatLng(-37.8136, 144.9631),
        zoom: 8
      }
    });
}
render() {
    ...
    return (
        ...
                    <div id="basic_map" style={{"width":"300px","height":"300px"}}></div>
        ...
    )
}

The problem here is the error "google not defined". I think it is from this line of code,

google.maps.LatLng(-37.8136, 144.9631),

Did I miss something in installation? How can I fix this? I am using Meteor, ReactJs, Flow router and TrackerReact


回答1:


That's because google hasn't been loaded yet. Make sure to check GoogleMaps.loaded() before you hit create.

The author, David Burles, wrote a nice example using the library with react, which should be helpful. It uses createContainer instead of TrackerReact but should get you on the right track.



来源:https://stackoverflow.com/questions/41256432/google-map-for-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!