【发布时间】:2017-05-15 07:00:57
【问题描述】:
我正在使用google-map-react NPM 包来创建一个谷歌地图和几个标记。
问题:我们如何将默认的 Google 地图标记添加到地图中?
From this Github issue,看来我们需要使用onGoogleApiLoaded 函数访问内部Google Maps API。
引用an example from the Google Maps JS API docs,我们可以使用下面的代码来渲染标记,但是我们如何定义对map的引用呢?
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
当前代码:
renderMarkers() {
...
}
render() {
return (
<div style={{'width':800,'height':800}}>
<GoogleMap
bootstrapURLKeys={{key: settings.googleMapApiKey}}
defaultZoom={13}
defaultCenter={{
lat: this.props.user.profile.location.coordinates[1],
lng: this.props.user.profile.location.coordinates[0]
}}
onGoogleApiLoaded={({map, maps}) => this.renderMarkers()}
yesIWantToUseGoogleMapApiInternals
>
</GoogleMap>
</div>
);
}
【问题讨论】:
标签: javascript google-maps reactjs meteor google-maps-api-3