DEV Community

loading...

Snippet: Grab lat/lon from Google Maps URL

Matt Kenefick
Senior Engineer -- Learn to code first. Use libraries second.
・1 min read

I needed to grab several latitude/longitude coordinates recently from Google Maps without using an API. This line can be executed in the console to quickly produce the coordinates derived from the URL.

[_, lat, lng] = location.href.match(/@([-0-9]+\.[0-9]+),([-0-9]+\.[0-9]+),/); console.log(lat, lng);
// 39.9532614 -75.1539449
Enter fullscreen mode Exit fullscreen mode

Discussion (0)