Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get user location javascript

geolocationSupported();

function geolocationSupported() {
  if (navigator.geolocation) {
    console.log("Geolocation is supported by this browser :)");
    getCurrentLocation();
  } else {
    console.log("Geolocation is NOT supported by this browser :(");
  }
}

function getCurrentLocation() {
  navigator.geolocation.getCurrentPosition(function(result) {
    result.coords.latitude; // latitude value
    result.coords.longitude; // longitude value
  });
}
Source by openjavascript.info #
 
PREVIOUS NEXT
Tagged: #user #location #javascript
ADD COMMENT
Topic
Name
9+8 =