【问题标题】:Show google maps component in admin-on-rest panel在 admin-on-rest 面板中显示谷歌地图组件
【发布时间】:2017-05-22 19:23:09
【问题描述】:

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

有人看吗?

谢谢。

【问题讨论】:

标签: google-maps reactjs admin-on-rest


【解决方案1】:
  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%` }} />}/> 

希望对你有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    相关资源
    最近更新 更多