In my app, I am utilizing the react-native-google-places-autocomplete package for two fields: Current Location and Destination. The Current Location field functions flawlessly without any errors once the location is entered and the lat/lng values are set using details.geometry.location
. However, an unexpected typeError arises after setting the Destination location. Below is the relevant code snippet.
<GooglePlacesAutocomplete
placeholder=""
query={{
key: GOOGLE_PLACES_API_KEY,
language: 'en', // language of the results
}}
onPress={(data, details:any) => {
setDestinationLatitude(details.geometry.location.lat.toString());
setDestinationLongitude(details.geometry.location.lng.toString());
}}
onFail={(error) => console.error(error)}
requestUrl={{
url:
'https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api',
useOnPlatform: 'web',
}} // this in only required for use on the web. See https://git.io/JflFv more for details.
keyboardShouldPersistTaps='always'
styles={{
textInputContainer: {
width: "90%",
alignSelf: 'center'
},
textInput: {
borderColor: grey,
borderWidth: 1,
borderRadius: 5,
height: 48,
paddingBottom: 8,
color: black,
fontSize: 16,
},
predefinedPlacesDescription: {
color: '#1faadb',
},
}}
/>
The above code snippet mirrors what I use for the Current Location field. Why then am I encountering a typeError when they are essentially identical? The only variance lies in the destinationlatitude and destinationlongitude parameters.