Can't set state when onRadiusChanged










0














I can not set state in this code. I understand it because I did not bind the function getvalue. Otherwise I cannot call this.radius. I this code this.radius is 5000. If I changed it to



 getvalues = (e)=> console.log(e) 


it returns undefined.



So what do I need to do



class Mapspage extends React.Component 
constructor(props)
super(props);
this.state =
location: lat: 52.2387683, lng: 5.8322737 ,
position: ,
radius: 5000,
;


getvalues(e)
this.setState('radius': this.radius);


render()
const MapWithAMarker = withGoogleMap(props => (
<GoogleMap
defaultZoom=11
defaultCenter=this.state.location
>
<Circle
radius=this.state.radius
editable=true
onRadiusChanged=this.getvalues
onDragEnd=this.getvalues
draggable=true
visible=true
center=this.state.location
/>
</GoogleMap>
));

return (
<div className="box box-default">
<MapWithAMarker
containerElement=<div style= height: `400px` />
mapElement=<div style= height: `100%` />
/>
</div>
);











share|improve this question




























    0














    I can not set state in this code. I understand it because I did not bind the function getvalue. Otherwise I cannot call this.radius. I this code this.radius is 5000. If I changed it to



     getvalues = (e)=> console.log(e) 


    it returns undefined.



    So what do I need to do



    class Mapspage extends React.Component 
    constructor(props)
    super(props);
    this.state =
    location: lat: 52.2387683, lng: 5.8322737 ,
    position: ,
    radius: 5000,
    ;


    getvalues(e)
    this.setState('radius': this.radius);


    render()
    const MapWithAMarker = withGoogleMap(props => (
    <GoogleMap
    defaultZoom=11
    defaultCenter=this.state.location
    >
    <Circle
    radius=this.state.radius
    editable=true
    onRadiusChanged=this.getvalues
    onDragEnd=this.getvalues
    draggable=true
    visible=true
    center=this.state.location
    />
    </GoogleMap>
    ));

    return (
    <div className="box box-default">
    <MapWithAMarker
    containerElement=<div style= height: `400px` />
    mapElement=<div style= height: `100%` />
    />
    </div>
    );











    share|improve this question


























      0












      0








      0


      0





      I can not set state in this code. I understand it because I did not bind the function getvalue. Otherwise I cannot call this.radius. I this code this.radius is 5000. If I changed it to



       getvalues = (e)=> console.log(e) 


      it returns undefined.



      So what do I need to do



      class Mapspage extends React.Component 
      constructor(props)
      super(props);
      this.state =
      location: lat: 52.2387683, lng: 5.8322737 ,
      position: ,
      radius: 5000,
      ;


      getvalues(e)
      this.setState('radius': this.radius);


      render()
      const MapWithAMarker = withGoogleMap(props => (
      <GoogleMap
      defaultZoom=11
      defaultCenter=this.state.location
      >
      <Circle
      radius=this.state.radius
      editable=true
      onRadiusChanged=this.getvalues
      onDragEnd=this.getvalues
      draggable=true
      visible=true
      center=this.state.location
      />
      </GoogleMap>
      ));

      return (
      <div className="box box-default">
      <MapWithAMarker
      containerElement=<div style= height: `400px` />
      mapElement=<div style= height: `100%` />
      />
      </div>
      );











      share|improve this question















      I can not set state in this code. I understand it because I did not bind the function getvalue. Otherwise I cannot call this.radius. I this code this.radius is 5000. If I changed it to



       getvalues = (e)=> console.log(e) 


      it returns undefined.



      So what do I need to do



      class Mapspage extends React.Component 
      constructor(props)
      super(props);
      this.state =
      location: lat: 52.2387683, lng: 5.8322737 ,
      position: ,
      radius: 5000,
      ;


      getvalues(e)
      this.setState('radius': this.radius);


      render()
      const MapWithAMarker = withGoogleMap(props => (
      <GoogleMap
      defaultZoom=11
      defaultCenter=this.state.location
      >
      <Circle
      radius=this.state.radius
      editable=true
      onRadiusChanged=this.getvalues
      onDragEnd=this.getvalues
      draggable=true
      visible=true
      center=this.state.location
      />
      </GoogleMap>
      ));

      return (
      <div className="box box-default">
      <MapWithAMarker
      containerElement=<div style= height: `400px` />
      mapElement=<div style= height: `100%` />
      />
      </div>
      );








      node.js reactjs google-maps react-google-maps






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 15:49









      Thakur Karthik

      389213




      389213










      asked Nov 11 at 11:16









      Wouter

      11219




      11219






















          2 Answers
          2






          active

          oldest

          votes


















          0














          I found the answer. You need to ref the circle component and then you can call the getValues function. Also you need tot return false the shouldComponentUpdate



          This is the code



          class Mapspage extends React.Component 
          constructor(props)
          super(props);

          this.state =
          location: lat: 52.2387683, lng: 5.8322737 ,
          position: ,
          radius: 5000
          ;

          mapMounted = ref =>
          this.map = ref;
          ;

          shouldComponentUpdate(nextProps, nextState)
          return false;


          getvalues = e =>
          const radius = this.map.getRadius();
          const center = this.map.getCenter();
          this.setState( radius: radius );
          this.setState(
          "location.lat": center.lat(),
          "location.lng": center.lng()
          );
          ;

          render()
          const MapWithAMarker = withGoogleMap(props => (
          <GoogleMap defaultZoom=11 defaultCenter=this.state.location>
          <Circle
          ref=this.mapMounted.bind(this)
          radius=this.state.radius
          editable=true
          onRadiusChanged=props.getval
          onDragEnd=props.getval
          draggable=true
          visible=true
          center=this.state.location
          />
          </GoogleMap>
          ));

          return (
          <div className="box box-default">
          <MapWithAMarker
          getval=this.getvalues.bind(this)
          containerElement=<div style= height: `400px` />
          mapElement=<div style= height: `100%` />
          />
          </div>
          );







          share|improve this answer




























            -1














            Please try this, the issue seems to be with binding.



            class Mapspage extends React.Component 
            constructor(props)
            super(props);
            this.state =
            location: lat: 52.2387683, lng: 5.8322737 ,
            position: ,
            radius: 5000,
            ;


            getvalues = (e) =>
            this.setState(radius: this.radius);


            render()
            const MapWithAMarker = withGoogleMap(props => (
            <GoogleMap
            defaultZoom=11
            defaultCenter=this.state.location
            >
            <Circle
            radius=this.state.radius
            editable=true
            onRadiusChanged=this.getvalues
            onDragEnd=this.getvalues
            draggable=true
            visible=true
            center=this.state.location
            />
            </GoogleMap>
            ));

            return (
            <div className="box box-default">
            <MapWithAMarker
            containerElement=<div style= height: `400px` />
            mapElement=<div style= height: `100%` />
            />
            </div>
            );







            share|improve this answer




















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248165%2fcant-set-state-when-onradiuschanged%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              I found the answer. You need to ref the circle component and then you can call the getValues function. Also you need tot return false the shouldComponentUpdate



              This is the code



              class Mapspage extends React.Component 
              constructor(props)
              super(props);

              this.state =
              location: lat: 52.2387683, lng: 5.8322737 ,
              position: ,
              radius: 5000
              ;

              mapMounted = ref =>
              this.map = ref;
              ;

              shouldComponentUpdate(nextProps, nextState)
              return false;


              getvalues = e =>
              const radius = this.map.getRadius();
              const center = this.map.getCenter();
              this.setState( radius: radius );
              this.setState(
              "location.lat": center.lat(),
              "location.lng": center.lng()
              );
              ;

              render()
              const MapWithAMarker = withGoogleMap(props => (
              <GoogleMap defaultZoom=11 defaultCenter=this.state.location>
              <Circle
              ref=this.mapMounted.bind(this)
              radius=this.state.radius
              editable=true
              onRadiusChanged=props.getval
              onDragEnd=props.getval
              draggable=true
              visible=true
              center=this.state.location
              />
              </GoogleMap>
              ));

              return (
              <div className="box box-default">
              <MapWithAMarker
              getval=this.getvalues.bind(this)
              containerElement=<div style= height: `400px` />
              mapElement=<div style= height: `100%` />
              />
              </div>
              );







              share|improve this answer

























                0














                I found the answer. You need to ref the circle component and then you can call the getValues function. Also you need tot return false the shouldComponentUpdate



                This is the code



                class Mapspage extends React.Component 
                constructor(props)
                super(props);

                this.state =
                location: lat: 52.2387683, lng: 5.8322737 ,
                position: ,
                radius: 5000
                ;

                mapMounted = ref =>
                this.map = ref;
                ;

                shouldComponentUpdate(nextProps, nextState)
                return false;


                getvalues = e =>
                const radius = this.map.getRadius();
                const center = this.map.getCenter();
                this.setState( radius: radius );
                this.setState(
                "location.lat": center.lat(),
                "location.lng": center.lng()
                );
                ;

                render()
                const MapWithAMarker = withGoogleMap(props => (
                <GoogleMap defaultZoom=11 defaultCenter=this.state.location>
                <Circle
                ref=this.mapMounted.bind(this)
                radius=this.state.radius
                editable=true
                onRadiusChanged=props.getval
                onDragEnd=props.getval
                draggable=true
                visible=true
                center=this.state.location
                />
                </GoogleMap>
                ));

                return (
                <div className="box box-default">
                <MapWithAMarker
                getval=this.getvalues.bind(this)
                containerElement=<div style= height: `400px` />
                mapElement=<div style= height: `100%` />
                />
                </div>
                );







                share|improve this answer























                  0












                  0








                  0






                  I found the answer. You need to ref the circle component and then you can call the getValues function. Also you need tot return false the shouldComponentUpdate



                  This is the code



                  class Mapspage extends React.Component 
                  constructor(props)
                  super(props);

                  this.state =
                  location: lat: 52.2387683, lng: 5.8322737 ,
                  position: ,
                  radius: 5000
                  ;

                  mapMounted = ref =>
                  this.map = ref;
                  ;

                  shouldComponentUpdate(nextProps, nextState)
                  return false;


                  getvalues = e =>
                  const radius = this.map.getRadius();
                  const center = this.map.getCenter();
                  this.setState( radius: radius );
                  this.setState(
                  "location.lat": center.lat(),
                  "location.lng": center.lng()
                  );
                  ;

                  render()
                  const MapWithAMarker = withGoogleMap(props => (
                  <GoogleMap defaultZoom=11 defaultCenter=this.state.location>
                  <Circle
                  ref=this.mapMounted.bind(this)
                  radius=this.state.radius
                  editable=true
                  onRadiusChanged=props.getval
                  onDragEnd=props.getval
                  draggable=true
                  visible=true
                  center=this.state.location
                  />
                  </GoogleMap>
                  ));

                  return (
                  <div className="box box-default">
                  <MapWithAMarker
                  getval=this.getvalues.bind(this)
                  containerElement=<div style= height: `400px` />
                  mapElement=<div style= height: `100%` />
                  />
                  </div>
                  );







                  share|improve this answer












                  I found the answer. You need to ref the circle component and then you can call the getValues function. Also you need tot return false the shouldComponentUpdate



                  This is the code



                  class Mapspage extends React.Component 
                  constructor(props)
                  super(props);

                  this.state =
                  location: lat: 52.2387683, lng: 5.8322737 ,
                  position: ,
                  radius: 5000
                  ;

                  mapMounted = ref =>
                  this.map = ref;
                  ;

                  shouldComponentUpdate(nextProps, nextState)
                  return false;


                  getvalues = e =>
                  const radius = this.map.getRadius();
                  const center = this.map.getCenter();
                  this.setState( radius: radius );
                  this.setState(
                  "location.lat": center.lat(),
                  "location.lng": center.lng()
                  );
                  ;

                  render()
                  const MapWithAMarker = withGoogleMap(props => (
                  <GoogleMap defaultZoom=11 defaultCenter=this.state.location>
                  <Circle
                  ref=this.mapMounted.bind(this)
                  radius=this.state.radius
                  editable=true
                  onRadiusChanged=props.getval
                  onDragEnd=props.getval
                  draggable=true
                  visible=true
                  center=this.state.location
                  />
                  </GoogleMap>
                  ));

                  return (
                  <div className="box box-default">
                  <MapWithAMarker
                  getval=this.getvalues.bind(this)
                  containerElement=<div style= height: `400px` />
                  mapElement=<div style= height: `100%` />
                  />
                  </div>
                  );








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 11 at 15:50









                  Wouter

                  11219




                  11219























                      -1














                      Please try this, the issue seems to be with binding.



                      class Mapspage extends React.Component 
                      constructor(props)
                      super(props);
                      this.state =
                      location: lat: 52.2387683, lng: 5.8322737 ,
                      position: ,
                      radius: 5000,
                      ;


                      getvalues = (e) =>
                      this.setState(radius: this.radius);


                      render()
                      const MapWithAMarker = withGoogleMap(props => (
                      <GoogleMap
                      defaultZoom=11
                      defaultCenter=this.state.location
                      >
                      <Circle
                      radius=this.state.radius
                      editable=true
                      onRadiusChanged=this.getvalues
                      onDragEnd=this.getvalues
                      draggable=true
                      visible=true
                      center=this.state.location
                      />
                      </GoogleMap>
                      ));

                      return (
                      <div className="box box-default">
                      <MapWithAMarker
                      containerElement=<div style= height: `400px` />
                      mapElement=<div style= height: `100%` />
                      />
                      </div>
                      );







                      share|improve this answer

























                        -1














                        Please try this, the issue seems to be with binding.



                        class Mapspage extends React.Component 
                        constructor(props)
                        super(props);
                        this.state =
                        location: lat: 52.2387683, lng: 5.8322737 ,
                        position: ,
                        radius: 5000,
                        ;


                        getvalues = (e) =>
                        this.setState(radius: this.radius);


                        render()
                        const MapWithAMarker = withGoogleMap(props => (
                        <GoogleMap
                        defaultZoom=11
                        defaultCenter=this.state.location
                        >
                        <Circle
                        radius=this.state.radius
                        editable=true
                        onRadiusChanged=this.getvalues
                        onDragEnd=this.getvalues
                        draggable=true
                        visible=true
                        center=this.state.location
                        />
                        </GoogleMap>
                        ));

                        return (
                        <div className="box box-default">
                        <MapWithAMarker
                        containerElement=<div style= height: `400px` />
                        mapElement=<div style= height: `100%` />
                        />
                        </div>
                        );







                        share|improve this answer























                          -1












                          -1








                          -1






                          Please try this, the issue seems to be with binding.



                          class Mapspage extends React.Component 
                          constructor(props)
                          super(props);
                          this.state =
                          location: lat: 52.2387683, lng: 5.8322737 ,
                          position: ,
                          radius: 5000,
                          ;


                          getvalues = (e) =>
                          this.setState(radius: this.radius);


                          render()
                          const MapWithAMarker = withGoogleMap(props => (
                          <GoogleMap
                          defaultZoom=11
                          defaultCenter=this.state.location
                          >
                          <Circle
                          radius=this.state.radius
                          editable=true
                          onRadiusChanged=this.getvalues
                          onDragEnd=this.getvalues
                          draggable=true
                          visible=true
                          center=this.state.location
                          />
                          </GoogleMap>
                          ));

                          return (
                          <div className="box box-default">
                          <MapWithAMarker
                          containerElement=<div style= height: `400px` />
                          mapElement=<div style= height: `100%` />
                          />
                          </div>
                          );







                          share|improve this answer












                          Please try this, the issue seems to be with binding.



                          class Mapspage extends React.Component 
                          constructor(props)
                          super(props);
                          this.state =
                          location: lat: 52.2387683, lng: 5.8322737 ,
                          position: ,
                          radius: 5000,
                          ;


                          getvalues = (e) =>
                          this.setState(radius: this.radius);


                          render()
                          const MapWithAMarker = withGoogleMap(props => (
                          <GoogleMap
                          defaultZoom=11
                          defaultCenter=this.state.location
                          >
                          <Circle
                          radius=this.state.radius
                          editable=true
                          onRadiusChanged=this.getvalues
                          onDragEnd=this.getvalues
                          draggable=true
                          visible=true
                          center=this.state.location
                          />
                          </GoogleMap>
                          ));

                          return (
                          <div className="box box-default">
                          <MapWithAMarker
                          containerElement=<div style= height: `400px` />
                          mapElement=<div style= height: `100%` />
                          />
                          </div>
                          );








                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 11 at 15:54









                          Muneer PP

                          694




                          694



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248165%2fcant-set-state-when-onradiuschanged%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Use pre created SQLite database for Android project in kotlin

                              Darth Vader #20

                              Ondo