在admin-on-rest面板中显示google maps组件

问题描述 投票:1回答:1

我正在尝试找到一个示例,说明如何在管理静止框架(https://github.com/istarkov/google-map-react)中使用任何Google Maps React组件(如此一个 - https://marmelab.com/admin-on-rest/)。

有人看一看吗?

谢谢。

google-maps reactjs admin-on-rest
1个回答
0
投票
  1. npm install --save react-google-maps#或yarn add react-google-maps
  2. import { GoogleMap,withScriptjs,withGoogleMap, Marker } from "react-google-maps"

3.

 export const MyMapComponent = withScriptjs(withGoogleMap((props) =>
 <GoogleMap
    defaultZoom={8}
    defaultCenter={{ lat: 24.715297, lng: 46.671848 }}>
    {props.isMarkerShown && <Marker position={{ lat: 24.715297, lng: 46.671848 }} />}

  </GoogleMap>))
  1. 例如,在你的export const postCreate中调用它
<MyMapComponent
  isMarkerShown
  googleMapURL="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places"
  loadingElement={<div style={{ height: `100%` }} />}
  containerElement={<div style={{ height: `400px`,width:`500px`,paddingTop:`100px` }} />}
  mapElement={<div style={{ height: `100%` }} />}/> 

希望这个帮助

© www.soinside.com 2019 - 2024. All rights reserved.