Reactjs 如何在谷歌地图中传递道具数据

Reactjs 如何在谷歌地图中传递道具数据,reactjs,google-maps,Reactjs,Google Maps,我正在使用谷歌地图制作一个小地图应用程序 下面是我的代码: import React, {Component} from "react"; import {Map, InfoWindow, Marker, GoogleApiWrapper} from 'google-maps-react'; class App extends Component { constructor(props) { super(props); } render() {

我正在使用谷歌地图制作一个小地图应用程序 下面是我的代码:

import React, {Component} from "react";
import {Map, InfoWindow, Marker, GoogleApiWrapper} from 'google-maps-react';

class App extends Component {
  constructor(props) {
    super(props);
  }
  
  render() {
    const style = {
      width: '50%',
      height: '50%'
    }
    const latUse = this.props.userdata[id - 1].address.geo.lat;
    const lngUse = this.props.userdata[id - 1].address.geo.lng;
    return(
      <Map
          google={this.props.google}
          style={style}
          initialCenter={{
            lat: 35.574138,
            lng: 85.088848
          }}
          zoom={15}
          onClick={this.onMapClicked}
        />
    )
  }
}

export default GoogleApiWrapper({
  apiKey: "...MYAPIKEY..."
})(App)
import React,{Component}来自“React”;
从“GoogleMaps react”导入{Map,InfoWindow,Marker,GoogleApiWrapper};
类应用程序扩展组件{
建造师(道具){
超级(道具);
}
render(){
常量样式={
宽度:“50%”,
身高:“50%”
}
const-latUse=this.props.userdata[id-1].address.geo.lat;
const lngUse=this.props.userdata[id-1].address.geo.lng;
返回(
)
}
}
导出默认GoogleApprapper({
apiKey:“…我的apiKey…”
})(应用程序)
正如您所见,我已经给出了
lat
lng
的坐标。但是我不想直接写坐标,而是想添加
latUse
lngUse
,通过我的道具获取坐标


我是个新手,不知道该怎么做。我只想将
lat
lng
的硬编码坐标替换为
latUse
lngUse

抱歉,但不确定您的意思。。。你为什么不试着这样写呢?initialCenter={{lat:latUse,lngUse}}您确实可以直接将latUse和lngUse作为您的initialCenter lat lng的值,正如上面web sudo所回答的。这里有一个问题,请从您的问题中删除您的API密钥,并且请不要在公共网站上共享这些密钥。