0

I'm dealing with a react-native project. I retrieved the current location of the user and I have this object returned:

  "coords": Object {
    "accuracy": 104.0999984741211,
    "altitude": 0,
    "heading": 0,
    "latitude": 34.4030088,
    "longitude": 35.8367525,
    "speed": 0,
  },
  "mocked": false,
  "timestamp": 1586419702795,
}

I tried this: 

console.log(this.state.location.coords.latitude); 
but it give me: ** undefined is not an object (evaluating 'this.state.location.coords.latitude') **
K_north
  • 13
  • 1
  • 1
    See the [linked question's answers](https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) for just about everything you need to know about accessing properties in objects. The question doesn't have enough information for us to help you specifically with it. Assuming the object you've shown is on `this.state.location`, your code for accessing `latitude` is correct, so either it isn't on `this.state.location` or the values aren't there *yet* because you're trying to access them before they're populated. See... – T.J. Crowder Apr 09 '20 at 08:17
  • ...the answers [here](https://stackoverflow.com/questions/23667086/) and [here](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) for help if it's the timing issue. – T.J. Crowder Apr 09 '20 at 08:17

0 Answers0