【发布时间】:2019-07-18 08:03:40
【问题描述】:
我是 React 新手,正在尝试使用谷歌地图来显示路线。我已经能够让它显示一个标记,但还没有找到如何重新配置代码来显示方向。以下是我最近的尝试,但它只会显示地图......感谢任何帮助:
import React, { Component } from 'react';
import { withGoogleMap, GoogleMap, DirectionsRenderer } from 'react-google-maps';
class Map extends Component {
render() {
const GoogleMapExample = withGoogleMap(props => (
<GoogleMap
defaultCenter = { { lat: 40.756795, lng: -73.954298 } }
defaultZoom = { 13 }
>
<DirectionsRenderer origin={{ lat: 40.756795, lng: -73.954298 }} destination={{ lat: 41.756795, lng: -78.954298 }} />
</GoogleMap>
));
return(
<div>
<GoogleMapExample
containerElement={ <div style={{ height: `500px`, width: '500px' }} /> }
mapElement={ <div style={{ height: `100%` }} /> }
/>
</div>
);
}
};
export default Map;
我在 index.html 的脚本标签中有 API 密钥
【问题讨论】:
标签: reactjs google-maps react-google-maps