作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Meteor 中安装了“meteor add dburles:google-maps”。我将此代码添加到 React 组件中,
...
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>
...
)
}
这里的问题是错误“google not defined”。我认为是从这行代码,
google.maps.LatLng(-37.8136, 144.9631),
我在安装过程中遗漏了什么吗?我怎样才能解决这个问题?我正在使用 Meteor、ReactJs、Flow router 和 TrackerReact
最佳答案
那是因为 google 还没有加载。在点击创建之前,请务必检查 GoogleMaps.loaded()
。
作者 David Burles 写了一个很好的 example using the library with react ,应该会有帮助。它使用 createContainer 而不是 TrackerReact,但应该能让您走上正轨。
关于javascript - meteor 的谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41256432/
leaflet:一个开源并且对移动端友好的交互式地图 JavaScript 库 中文文档: https://leafletjs.cn/reference.html 官网(英文): ht
我是一名优秀的程序员,十分优秀!