1 year ago

#250327

test-img

alia

GooglePlacesAutocomplete in react native gets inaccurate latitude and longitude

I need to add Google Places Autocomplete in my react-native app, I'm using react-native-google-places-autocomplete library, my code is:

 <GooglePlacesAutocomplete
              placeholder="Search address"
              fetchDetails={true}
              onPress={(data, details = null) => {
                // 'details' is provided when fetchDetails = true
                let lat = details.geometry.location.lat;
                let lng = details.geometry.location.lng;
                console.log(lat, lng)
                 }
              query={{
                key: GooglePlacesAPIKey,
                language: 'en',
                //components: 'country:us',
              }}
            />
        

When I console.log(lat, lng) after onPress event I get incorrect latitude and longitude, for example, if I selected from drop down menu a street in Manhattan, latitude and longitude may be for the similar street name in Queens, or Brooklyn. Why is this happening? Any help and advice is greatly appreciated.

javascript

react-native

google-maps

google-places

0 Answers

Your Answer

Accepted video resources