Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 无法从RadiusChanged事件上的可编辑圆获取半径值_Reactjs_Google Maps_React Google Maps - Fatal编程技术网

Reactjs 无法从RadiusChanged事件上的可编辑圆获取半径值

Reactjs 无法从RadiusChanged事件上的可编辑圆获取半径值,reactjs,google-maps,react-google-maps,Reactjs,Google Maps,React Google Maps,我是谷歌地图的新手。我无法从圆中获取半径值 我想在RadiusChanged事件中获取圆半径 index.js map.js 结果- 未定义 onRadiusChanged作为Circle类事件的基础不接受任何参数。由于在您的示例中,onRadiusChanged事件处理程序方法未与其组件实例绑定,因此更新后的radius可以如下确定: updateRadius() { const updatedRadius = this.getRadius(); } 这里指的是本地的 import

我是谷歌地图的新手。我无法从圆中获取半径值

我想在RadiusChanged事件中获取圆半径

index.js

map.js

结果-

未定义

onRadiusChanged作为Circle类事件的基础不接受任何参数。由于在您的示例中,onRadiusChanged事件处理程序方法未与其组件实例绑定,因此更新后的radius可以如下确定:

updateRadius() {
    const updatedRadius = this.getRadius();
}
这里指的是本地的

import React, { Component } from "react";
import {
  withScriptjs,
  withGoogleMap,
  GoogleMap,
  Marker,
  Circle
} from "react-google-maps";

class MyMapComponent extends Component {

  constructor(props) {
        super(props);
        this.state = {
          radius: 50
        }
  }

  updateRadius(e) {
    console.log(e);
  }

  render() {
    return (
      <GoogleMap
        defaultZoom={this.props.zoom}
        defaultCenter={this.props.center}
      >
      <Marker google={this.props.google}
        name={'Dolores park'}
        draggable={true}
        onDragEnd={this.onMarkerDragEnd}
        position={this.props.center}
      />
        <Circle
          center={this.props.center}
          options={{
            strokeColor: "#FF0000",
            strokeOpacity: 0.8,
            strokeWeight: 1,
            fillColor: "#FF0000",
            fillOpacity: 0.35,
            clickable: false,
            draggable: false,
            editable: true,
            visible: true,
            radius: this.state.radius, //Calculation in Meter
            zIndex: 1
          }}
          onRadiusChanged={this.updateRadius}
        />
      </GoogleMap>
    );
  }
}

export default withScriptjs(withGoogleMap(MyMapComponent));
updateRadius() {
    const updatedRadius = this.getRadius();
}