Javascript 谷歌流星地图
我在meteor中安装了“meteor添加dburles:google地图”。我将此代码添加到React组件中Javascript 谷歌流星地图,javascript,google-maps,reactjs,meteor,flow-router,Javascript,Google Maps,Reactjs,Meteor,Flow Router,我在meteor中安装了“meteor添加dburles:google地图”。我将此代码添加到React组件中 ... import { GoogleMaps } from 'meteor/dburles:google-maps'; ... export default class Location extends TrackerReact(React.Component){ constructor(props) { super(props); this.state = {
...
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>
...
)
}
我在安装过程中遗漏了什么吗?我怎样才能解决这个问题?
我正在使用Meteor、ReactJs、Flow router和TrackerReact,这是因为google还没有加载。在点击“创建”之前,请确保选中
GoogleMaps.loaded()
作者David Burles写了一篇不错的文章,应该会有帮助。它使用createContainer而不是TrackerReact,但应该会让您走上正确的轨道。我将GoogleMaps.loaded()放在哪里?@JohnArellano好吧,如果我查看TrackerReact文档,它会说:“任何反应性数据源(例如:collection.find()或Session.get('foo'))在渲染方法中使用或由渲染方法调用的方法自动响应!”因此我将其插入渲染方法中的an if语句中,并仅在其为真时执行
create
。仍然存在错误“google未定义”。我在render和before return语句中使用了if(GoogleMaps.loaded()),谢谢。我已经解决了这个问题,但是有一个新的错误,GoogleMapsAPI错误:MissingKeyMapError我认为您必须提供GoogleMaps.load()的密钥,如图和所示
google.maps.LatLng(-37.8136, 144.9631),