3

Hi im using react native and I want to get my current locations city name can anyone help me with this issue?? I dont get the response at all. I have already tried...

Code:

 componentDidMount(){
        navigator.geolocation.getCurrentPosition(
          (position) => {
            try {
                Geocoder.geocodePosition({ position.coords.latitude, position.coords.longitude }.then(res =>
                  console.log(res);
             } catch(err) {
               console.log(err);
             }
           },
           (error) => this.setState({ error: error.message }),
           { enableHighAccuracy: false, timeout: 200000, maximumAge: 1000 },
         );
  }
Nijaahnandh
  • 95
  • 1
  • 1
  • 7

2 Answers2

2

React Native did not support Inverse Geocoding (from location to administrative information). Check this answer : Use Geocoder to return the device address

Walter Palladino
  • 479
  • 1
  • 3
  • 8
0

Solution:

if (results[0]) {
  var add= results[0].formatted_address;
  var  value=add.split(",");
  count=value.length;
  city=value[count-3];
  x.innerHTML = "city name is: " + city;
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31