如何解决InvalidValueError:setMap:不是Map的实例;而不是StreetViewPanorama @ react-google-maps / api
我正在使用@ react-google-maps / api并将脚本从CDN加载到我的公共目录index.html文件中。
我得到InvalidValueError: setMap: not an instance of Map; and not an instance of StreetViewPanorama
,但标记没有出现在我的地图上。奇怪的是,得到这个错误是完全随机的。有时它可以正常工作。首先我是不明白的。
import React,{ useEffect } from 'react';
import { GoogleMap,Marker } from '@react-google-maps/api';
import mapStyles from './mapStyles';
//google map height 100
import './MapDisplay.css';
import { connect } from 'react-redux';
const mapContainerStyle = {
height: '100%',width: '100%',};
const options = {
styles: mapStyles,disableDefaultUI: true,zoomControl: true,};
const MapDisplay = ({
userLocation,mouseHoverIdR,selectedInfoR,searchedResults,unAuthNoSearchResults,selectedLocationInfoWindowS,}) => {
const onClickMarker = (e) => {
selectedLocationInfoWindowS({
selectedInfoR: e,type: 'infoWindowLocations',});
};
const onClickMap = () => {
selectedLocationInfoWindowS({
type: '',selectedInfoR: {
_id: '',},});
};
return (
<div id='map'>
<GoogleMap
id='map_canvas'
mapContainerStyle={mapContainerStyle}
zoom={12}
center={userLocation}
options={options}
onClick={() => onClickMap()}
>
{!unAuthNoSearchResults &&
searchedResults.map((searchedResult) => {
if (
mouseHoverIdR === searchedResult._id ||
selectedInfoR._id === searchedResult._id
) {
var a = window.google.maps.Animation.BOUNCE;
}
return (
<Marker
position={searchedResult.coordinates}
key={searchedResult._id}
clickable
onClick={() => onClickMarker(searchedResult)}
animation={a}
id={'hello'}
/>
);
})}
</GoogleMap>
</div>
);
};
当我尝试在地图上显示标记时,如何解决出现的错误?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。