Skip to content
Advertisement

How to get Longitude and Latitude from Google Map URL [closed]

I want to extract longitude and Latitude from Google Map URL Is this possible to use Jquery to extract them Like

https://www.google.com/maps/place/Arctic+Pixel+Digital+Solutions/@63.6741553,-164.9587713,4z/data=!3m1!4b1!4m5!3m4!1s0x5133b2ed09c706b9:0x66deacb5f48c5d57!8m2!3d64.751111!4d-147.3494442

The Longitude and latitude are Logitude : 63.6741553 Latitude : -164.9587713

I want to extract them with jquery

Advertisement

Answer

var url = "https://www.google.com/maps/place/Arctic+Pixel+Digital+Solutions/@63.6741553,-164.9587713,4z/data=!3m1!4b1!4m5!3m4!1s0x5133b2ed09c706b9:0x66deacb5f48c5d57!8m2!3d64.751111!4d-147.3494442";
var regex = new RegExp('@(.*),(.*),');
var lat_long_match = url.match(regex);
var lat = lat_long_match[1];
var long = lat_long_match[2];

Based on the comment, I assume this is exactly what you’re looking for:

<script>
    $(function() {
        $('#btn').on('click', function() {
            var url = $('input[name=googlemapurl]').val();
            var regex = new RegExp('@(.*),(.*),');
            var lat_long_match = url.match(regex);
            var lat = lat_long_match[1];
            var long = lat_long_match[2];

            $('input[name=latitude]').val(lat);
            $('input[name=longitude]').val(long);
        });
    });
</script>

<p><input type="text" class="form-control" placeholder="Google Map Link" name="googlemapurl"/></p>
<p><input type="text" class="form-control" placeholder="GPS Latitude" name="latitude" /></p>
<p><input type="text" class="form-control" placeholder="GPS Longitude" name="longitude" /></p>
<p><button id="btn">Extract</button></p>
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement