0

I am trying to get the current location from latitude and longitude in react-native(Android), I have received latitude and longitude correctly but the result of the location returns as [object object]

constructor(props) {
  super(props);
  this.state = {
    latitude: null,
    longitude: null,
    error:null,
  };
}

componentDidMount() {
  navigator.geolocation.getCurrentPosition(
   (position) => {
     console.log("wokeeey");
     console.log(position);
     this.setState({
       latitude: position.coords.latitude,
       longitude: position.coords.longitude,
       error: null,
     });
   },
   (error) => this.setState({ error: error.message }),
   { enableHighAccuracy: false, timeout: 200000, maximumAge: 1000 },
  );
}


getData(){
  Geocoder.init("My_Api");
  Geocoder.from(this.state.latitude,this.state.longitude)
    .then(json => {
            var addressComponent = json.results[0].address_components[0];
        alert(addressComponent);
    })
    .catch(error => console.warn(error));
}
Andrew
  • 26,706
  • 9
  • 85
  • 101
  • 1
    try `alert(JSON.stringify(addressComponent))` or `alert(JSON.stringify(json.results[0].address_components))` and see what is output. And manage propogation accordingly. – Jaydeep Galani Feb 09 '19 at 06:11
  • Possible duplicate of [what does \[object Object\] mean?](https://stackoverflow.com/questions/4750225/what-does-object-object-mean) – robincEPtion Feb 09 '19 at 06:39

0 Answers0