googlemaps / googlemaps/google-maps-services-js

PlacesAutocomplete call crashes if the optional location field is present but undefined

Open
#1,052 3 comments 1 reaction 0 assignees View on GitHub
type: bug
Dominant language
TypeScript
Stars
3.1k
Forks
654
Avg merge
3m
Merged PRs (30d)
4

Description

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

```javascript
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 ()
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 ()
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:
```javascript
location: ...(myCoordinates ? { location: myCoordinates } : {}),
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.