How can I extract the Lat and Long from google maps shared link (https://goo.gl/maps/2vV46xBbqiKp18MQA)

124 Views Asked by At

The case that there is someone that will input a link in a form and I need to decode that link to get lat and long to place the pin on an embedded map for him

stack: JavaScript - Angular

the problem is the google maps shared link is like this https://goo.gl/maps/2vV46xBbqiKp18MQA

how can I extract the lat and long from this link using JavaScript

1

There are 1 best solutions below

7
ardentia On

A solution where you do not require users to give you an exact URL schema is to have logic that determines what the shortened link actually points to and then scrape its query params for lat and long values. See this answer: https://stackoverflow.com/a/72054044/17963017

Of course, you would need to make sure that the URL is valid, the domain points to Google Maps, etc.