【发布时间】:2019-03-28 17:48:27
【问题描述】:
我想在我的项目中为我当前的位置添加蓝点。我的地图文件的代码是这样的
状态是
this.state={
currentPosition:{lat: 26.84 ,lng: 75.80},
destinationPosition:{lat: 26.84 ,lng: 75.80}
};
当前位置的handleClick是
handleClick(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition((position)=>{
this.setState(()=>({
currentPosition:{
lat:position.coords.latitude,
lng:position.coords.longitude}}))
console.log(position.coords.latitude);
});
}
else{
alert("Geoloaction is not supported by your browser");
}
}
而render函数是这样的
render(){
const MyMapComponent = compose(
withProps({
googleMapURL: "https://maps.googleapis.com/maps/api/js?key=AIzaSyC5VMMlyr_A6K5ycpOrq3OsVM8YYbn0q3A&v=3.exp&libraries=geometry,drawing,places",
loadingElement: <div style={{ height: `100%` }} />,
containerElement: <div style={{ height: `300px` }} />,
mapElement: <div style={{ height: `100%` }} />,
}),
withScriptjs,
withGoogleMap
)((props) =>
<GoogleMap defaultZoom={15} defaultCenter=
{this.state.destinationPosition} >
<Marker position={this.state.destinationPosition} draggable
changeLat
onDragEnd={this.onMarkerPositionChanged.bind(this)}
/>
<Button bsStyle="success" onClick=
{this.handleClick.bind(this)}>Current Position</Button>
</GoogleMap>
);
return(
<Container
text={<Text lat={this.state.destinationPosition.lat}
lng={this.state.destinationPosition.lng}/>}
map={<MyMapComponent />}
/>
);
}
另外请告诉我如何在我的地图中同时包含标记和蓝点。
【问题讨论】:
标签: angularjs node.js reactjs react-google-maps