0

我通过 axios 和 setState 将地理编码位置获取到 latt,lngg 变量中,我想在 google-map-react 包中心使用这个变量我如何将这些状态值传递给 props 。

休息 API

then(res => {
  console.log(res.data.results[0].geometry.location.lat);
  console.log(res.data.results[0].geometry.location.lng);
  // console.log(res.data[0]);

  this.setState({latt:res.data.results[0].geometry.location.lat})
  this.setState({lngg:res.data.results[0].geometry.location.lng})
})

static defaultProps = {
  center: {
    lat: 32,
    lng: 56
  },
  zoom: 5.7
};

<GoogleMapReact bootstrapURLKeys={{ key:API-KEY}} defaultCenter={this.props.center} defaultZoom={this.props.zoom}>
4

1 回答 1

0

对于引用状态值,您将使用this.state.centerandthis.state.zoom而不是this.props.which 用于当前组件的道具。

于 2020-10-12T14:42:19.490 回答