我目前正在使用react-google-mapGoogle Map在我的React项目中运行,这是我的Map组件:
import React from 'react'
import { compose, withProps, lifecycle } from 'recompose'
import { withScriptjs, withGoogleMap, GoogleMap } from 'react-google-maps'
import MapStyle from '../../../api/mapStyle'
const Map = ({ children }) => {
return (
<GoogleMap
defaultZoom={15}
defaultCenter={{ lat: 35.6840299, lng: 51.3861187 }}
>
{children}
</GoogleMap>
)
}
export default compose(
withProps({
googleMapURL: "https://maps.googleapis.com/maps/api/js?key=MY_KEY_HERE",
loadingElement: <div style={{ height: `100%` }} />,
containerElement: <div className='map' style={{ height: `100vh` }} />,
mapElement: <div style={{ height: `100%` }} />
}), …Run Code Online (Sandbox Code Playgroud)