google-maps-services-js
google-maps-services-js copied to clipboard
PlacesAutocomplete call crashes if the optional location field is present but undefined
PlacesAutocomplete call crashes if the optional params.location field is present but undefined.
Environment details
OS: macOS Ventura 13.4 Library version: 3.3.41
Steps to reproduce
Call placesAutocomplete with { params: { ...rest, location: undefined } }
Code example
const response = await new Client({}).placeAutocomplete({
params: {
key: apiKey,
input,
radius: 50000,
location: undefined
},
})
Stack trace
Error: Cannot use 'in' operator to search for 'lat' in undefined
at dispatchHttpRequest (/app/node_modules/@googlemaps/google-maps-services-js/node_modules/axios/dist/node/axios.cjs:2797:25)
at /app/node_modules/@googlemaps/google-maps-services-js/node_modules/axios/dist/node/axios.cjs:2568:5
at new Promise (<anonymous>)
at wrapAsync (/app/node_modules/@googlemaps/google-maps-services-js/node_modules/axios/dist/node/axios.cjs:2548:10)
at http (/app/node_modules/@googlemaps/google-maps-services-js/node_modules/axios/dist/node/axios.cjs:2574:10)
at /app/node_modules/@googlemaps/google-maps-services-js/dist/adapter.js:66:9
at new Promise (<anonymous>)
at /app/node_modules/@googlemaps/google-maps-services-js/dist/adapter.js:65:12
at dispatchRequest (/app/node_modules/axios/lib/core/dispatchRequest.js:58:10)
at Axios.request (/app/node_modules/axios/lib/core/Axios.js:109:15)
If the location is completely unspecified, the function call works fine. This can be solved by defining location like:
location: ...(myCoordinates ? { location: myCoordinates } : {}),
If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.
@Jiia Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:
- Check the issue tracker - bugs and feature requests for Google Maps Platform APIs and SDKs
- Open a support case - Get 1:1 support in Cloud Console.
- Discord - chat with other developers
- StackOverflow - use the
google-mapstag
This is an automated message, feel free to ignore.
This seems to be the reason:
https://github.com/googlemaps/google-maps-services-js/blob/44ed812c133cee94a12d399af902b4f4173356be/src/serialize.ts#L27-L45
Treating undefined and null like an empty string should be a good solution here.