Darshan_'s avatar

Laravel Get Location

Hello,

How can we get current location of users using Laravel?

Can we integrate Google Geo Coding in Laravel? If yes, is there any code?

Please suggest!

0 likes
3 replies
zainudinnoori's avatar
Level 7

Try this:

<!DOCTYPE html>
<html>
<body>

<p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>

<script>
var x = document.getElementById("demo");

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else { 
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude;
}
</script>

</body>
</html>
1 like
Darshan_'s avatar

This is what i have done? But how do I get it in session variable to update it in database? I have been trying it in AJAX is there any other way?

Please or to participate in this conversation.