Hi,
I have simple JS code to get geolocation, geolocation is working, but the value is not stored in the variable I declared before if. They are seen if access from if but not once if is closed.
Please give me advice what I am doing wrong, thx here is my code:
$(document).ready(function()
{
var myLatitude = “”;
var myLongitude = “”;
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
//$("#data").html("latitude: " + position.coords.latitude + "
longitude: " + position.coords.longitude);
myLatitude = position.coords.latitude;
console.log("In if: " + myLatitude + " " + myLongitude);
myLongitude = position.coords.longitude;
});
}
console.log("After if: " + myLatitude + " " + myLongitude);
});