I want to make return latitude and longitude of the current user from the function and I have written the following code but this piece of code is saying "undefined" as a result. If anybody knows the solution, please answer
<script>
function getLocation() {
if (navigator.geolocation) {
var lat_lng = navigator.geolocation.getCurrentPosition(showPosition);
console.log(lat_lng);
} else {
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
var user_position = {};
user_position.lat = position.coords.latitude;
user_position.lng = position.coords.longitude;
return user_position;
}
getLocation()
</script>