【发布时间】:2019-08-18 23:43:59
【问题描述】:
鉴于以下数据:
[
{
"id": 1,
"name": "Park Slope",
"latitude": "40.6710729",
"longitude": "-73.9988001"
},
{
"id": 2,
"name": "Bushwick",
"latitude": "40.6942861",
"longitude": "-73.9389312"
},
{
"id": 3,
"name": "East New York",
"latitude": "40.6577799",
"longitude": "-73.9147716"
}
]
]
我正在通过react-google-maps 创建标记,如下所示:
<Map
center={{ lat: 40.64, lng: -73.96 }}
zoom={12}
places={data}
googleMapURL="https://maps.googleapis.com/maps/api/js?key="
loadingElement={<div style={{ height: `100%` }} />}
containerElement={<div style={{ height: `800px` }} />}
mapElement={<div style={{ height: `100%` }} />}
/>
在哪里
class Map extends React.Component {
render() {
return (
<GoogleMap
defaultZoom={this.props.zoom}
defaultCenter={this.props.center}
>
{this.props.places.map(place => {
return (
<Marker
position={{
lat: parseFloat(place.latitude),
lng: parseFloat(place.longitude)
}}
/>
);
})}
</GoogleMap>
);
}
}
现在我想连同标记一起渲染一个圆圈,但只针对特定标记,例如第一个位置:
{
"id": 1,
"name": "Park Slope",
"latitude": "40.6710729",
"longitude": "-73.9988001"
},
如下所示:
除了指定半径等属性外,是否支持通过react-google-maps进行渲染和圆?
【问题讨论】:
-
什么半径?基于什么?你想如何显示半径?作为文本?您的问题不清楚。
-
你仍然没有说你从哪里得到那个半径。我在发布的代码中看不到任何看起来像半径的东西(距离、米、公里或其他)。无论如何,要在标记下方显示一个圆圈,您需要创建一个 Circle。
标签: reactjs google-maps react-google-maps