Reactjs “谷歌地图反应”;“谷歌没有定义”;
我在我的一个react项目中使用了react谷歌地图。但我得到了一个错误:Reactjs “谷歌地图反应”;“谷歌没有定义”;,reactjs,undefined,react-google-maps,Reactjs,Undefined,React Google Maps,我在我的一个react项目中使用了react谷歌地图。但我得到了一个错误: google is not defined 我尝试过其他几种解决堆栈溢出的方法,但没有一种对我有效。 这是我的密码: /* global google */ import React, { useState } from 'react' import { GoogleMap, Marker, InfoWindow, HeatmapLayer, LoadScript } from '@react-google-maps/
google is not defined
我尝试过其他几种解决堆栈溢出的方法,但没有一种对我有效。
这是我的密码:
/* global google */
import React, { useState } from 'react'
import { GoogleMap, Marker, InfoWindow, HeatmapLayer, LoadScript } from '@react-google-maps/api';
import { markerPosition } from "./MapData";
... // other code
const ExampleTraffic = (props) => {
... // other code
return (
<LoadScript
id="script-loader"
googleMapsApiKey="My Api Key"
region="BD"
libraries={libraries}
>
<GoogleMap
id='example-map'
mapContainerStyle={{ height: "100vh", width: "100vw" }}
zoom={13}
center={{
lat: 23.684994,
lng: 90.356331
}}
clickableIcons={true}
>
... // other code
<HeatmapLayer data={[
new google.maps.LatLng(22.862257, 22.862257),
new google.maps.LatLng(22.853746, 89.534611),
new google.maps.LatLng(22.847735, 89.537359),
new google.maps.LatLng(22.845773, 89.551920),
new google.maps.LatLng(22.861434, 89.534056),
new google.maps.LatLng(22.864945, 89.514299),
new google.maps.LatLng(22.868741, 89.527406),
new google.maps.LatLng(22.866369, 89.528873),
new google.maps.LatLng(22.857052, 89.547997),
new google.maps.LatLng(22.845172, 89.530171),
new google.maps.LatLng(22.854094, 89.562946),
new google.maps.LatLng(22.868963, 89.507291),
new google.maps.LatLng(22.871177, 89.547143),
new google.maps.LatLng(22.897430, 89.513818)
]}
/>
</GoogleMap>
</LoadScript >
);
}
export default ExampleTraffic;
/*全球谷歌*/
从“React”导入React,{useState}
从'@react google maps/api'导入{GoogleMap,Marker,InfoWindow,HeatmapLayer,LoadScript};
从“/MapData”导入{markerPosition};
... // 其他代码
const ExampleTraffic=(道具)=>{
…//其他代码
返回(
…//其他代码
);
}
导出默认示例流量;
我的代码怎么了?非常感谢您的帮助。此问题已通过使用解决
new window.google.maps.LatLng(22.862257, 22.862257),
new window.google.maps.LatLng(22.853746, 89.534611),
而不是
new google.maps.LatLng(22.862257, 22.862257),
new google.maps.LatLng(22.853746, 89.534611),
该问题通过使用
new window.google.maps.LatLng(22.862257, 22.862257),
new window.google.maps.LatLng(22.853746, 89.534611),
而不是
new google.maps.LatLng(22.862257, 22.862257),
new google.maps.LatLng(22.853746, 89.534611),
如果你想使用
window.google
,你必须在公共文件夹的index.html
中添加一个谷歌api的脚本标签。但如果您已经在LoadScript
中定义了谷歌api。如果你能告诉我,你到底想做什么,我可以帮你使用谷歌{lat:37.782,lng:-122.447,weight:0.5},{lat:37.782,lng:-122.443,weight:2},{lat:37.782,lng:-122.441,weight:3},{lat 37.782,lng:-122.439,weight:2},{lat 37.782,lng:-122.435,weight:0.5},{lat:37.785,lng:-122.447,重量:3},{lat:37.785,lng:-122.445,重量:2},{lat:37.785,lng:-122.441,重量:0.5},{lat lat:37.785,lng:-122.437,重量:2},{lat 37.785,lng:-122.435,重量:3}如果您想使用窗口,请将格式化为数据中的道具。google
您必须在公用文件夹的index.html
中添加google api的脚本标记。但如果您已经在LoadScript
中定义了google api。如果您能告诉我,您到底想做什么,我可以帮助您使用谷歌{lat:37.782,lng:-122.447,重量:0.5},{lat:37.782,lng:-122.443,重量:2},{lat:37.782,lng:-122.441,重量:3},{lat:37.782,lng:-122.439,重量:2},{lat 37.782,lng:-122.435,重量:0.5},{lat 37.785,lng:-122.447,重量:3},{lat:37.785,lng:-122.445,重量:2},{lat:37.785,lng:-122.441,重量:0.5},{lat:37.785,lng:-122.437,重量:2},{lat:37.785,lng:-122.435,重量:3}
在的数据中作为支柱