函数 apiIsLoaded 没有被调用,并且 map 不能被初始化。怎么了?检查时,我可以看到没有谷歌地图 iframe 的 div,只是空白。我需要调用 apiIsLoaded,但找不到任何方法来做到这一点。这是代码,任何帮助将不胜感激。
import React from 'react';
import GoogleMapReact from "google-map-react";
const LocationMap = (props) => {
const apiIsLoaded = (map, maps) => {
if (map) {
map.setOptions({ gestureHandling: 'greedy', mapTypeControl: false, minZoom: 2});
}
};
const { address } = props;
const center = address ? { lat: address.lat, lng: address.lon } : { lat: 0, lng: 0 };
return (
<div className="google-maps-wrapper">
<GoogleMapReact
bootstrapURLKeys={{
key: process.env.REACT_APP_MAP_KEY
}}
defaultZoom={address ? 8 : 2}
center={[center.lat, center.lng]}
defaultCenter={[0, 0]}
yesIWantToUseGoogleMapApiInternals={true}
onGoogleApiLoaded={({ map, maps }) => apiIsLoaded(map, maps)}>
</GoogleMapReact>
</div>
);
};
export default LocationMap;