Search code examples
react-nativegoogle-geocodergoogle-geolocation

Want to get current location from react native js+google api key


I want to get current location in text/alert in react native want city name in text

Here my code:

getData(){

        Geocoder.init("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

        Geocoder.from(41.89, 12.49)
            .then(json => {
                var addressComponent = json.results[0].formatted_address;
          console.log(addressComponent);
          console.log(addressComponent)
         alert(addressComponent);
            })
          .catch(error => console.warn(error));
        }

Solution

  • getData(){
    
            Geocoder.init("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    
            Geocoder.from(41.89, 12.49)
                .then(json => {
                    var addressComponent = json.results[0].formatted_address;
              console.log(addressComponent);
              console.log(addressComponent)
             alert(addressComponent);
                })
              .catch(error => console.warn(error));
            }
    

    I want to combine this with current location latitude n longitude