-2

I have a variable called coordinates that is formatted like this:

var coordinates = 'lat / lon';

I now want to extract the single lat and lon coordinate from that variable to display it as the center in a Google Maps API Map. I have tried using slice to get the specific parts of the coordinates variable but depending on what coordinate it is the length is different, for example:

var coordinates = '49.7824 / 7.2413';
var coordinates = '8.5323 / -11.3336';

Is there any other way I could use those coordinates as the map center with the Maps API?

  • 3
    Have you considered `coordinates.split(" / ")[0]` ? – lucas Feb 23 '20 at 07:04
  • 1
    Duplicate of [How do I split a string, breaking at a particular character?](https://stackoverflow.com/questions/96428/how-do-i-split-a-string-breaking-at-a-particular-character) – MrUpsidown Feb 23 '20 at 10:58

1 Answers1

-1

var coordinates = '49.7824 / 7.2413';
const [lgt, lat] = coordinates.split('/');
Jim Jin
  • 1,249
  • 1
  • 15
  • 28
  • 2
    Please avoid answering questions that have been answered already (and multiple times). Instead, point the OP to the duplicate Q/A in a comment. Once you will have sufficient reputation, you will earn the [privilege](https://stackoverflow.com/help/privileges) to cast close votes. – MrUpsidown Feb 23 '20 at 11:02