0

I'm writing some JavaScript in VS Code that runs a query against the Google Maps Places Autocomplete API and Code won't allow me to enter a location option that has a negative longitude. I want this:

var options = {
  types: ['(cities)'],
  location: 34.05223,-118.24368
}

Code keeps putting a space between the minus sign and the rest of the digits in the longitude:

  location: 34.05223,- 118.24368

Is there some way to override this behavior? I've checked my Code extensions and don't see one (such as a linter) that I can disable.

Jim
  • 13,430
  • 26
  • 104
  • 155
  • 3
    You probably want to be using a string, and not a pair of numbers with a comma operator between them there. – Quentin Jul 24 '20 at 18:20
  • Regardless of spacing, that won't do what you expect. It looks like you want a comma-separated string: `"34.05223,-118.24368"` (although an array of 2 numbers would likely work better). – Robin Zigmond Jul 24 '20 at 18:20
  • Well, it's not valid JavaScript syntax. Check the API and see if it expects a string or list. – Jeppe Jul 24 '20 at 18:33
  • Using parentheses appears to be working OK. As for the API, it's Google maps and the doc page just says "location — The point around which you wish to retrieve place information. Must be specified as latitude,longitude." Not sure where to find the API source code itself. Thank you everyone for your comments! – Jim Jul 24 '20 at 21:28
  • @Jeppe - [it is valid syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator), just almost certainly not what the OP means. – Robin Zigmond Jul 24 '20 at 22:03
  • @RobinZigmond Try it out yourself, it is part of an object property declaration here. It at least requires parentheses to not throw an error. – Jeppe Jul 27 '20 at 07:03

0 Answers0