Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js get user location

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;
}
Comment

javascript get users location

if ("geolocation" in navigator) {
	navigator.geolocation.getCurrentPosition(function(position) {
		console.log("Longitude:", position.coords.longitude, "Latitude:", position.coords.latitude);
	});
}
Comment

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
  });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascaript 
Javascript :: bootstrap 4 form validator with jquery 
Javascript :: angular javascript 
Javascript :: formidable node js 
Javascript :: nodejs check if file is running on server or client 
Javascript :: Is there an “exists” function for jQuery 
Javascript :: jsfuck 
Javascript :: html js hide or show iframe 
Javascript :: run a local instance of ElasticSearch on docker 
Javascript :: js if the reverse of a number is better than the original num 
Javascript :: join in array 
Javascript :: how to do addition in javascript 
Javascript :: react hooks example 
Javascript :: check when input number value goes up or down 
Javascript :: same date to string in javascript minus and days difference 
Javascript :: beanstalk nodejs default port 
Javascript :: how to add debounce in react redux js 
Javascript :: Firebase: Error (auth/invalid-api-key). 
Javascript :: Function.prototype.bind polyfill 
Javascript :: ionicActionSheet decorator example 
Javascript :: what is react mounting 
Javascript :: file-loader support json file 
Javascript :: django csrf failed ajax 
Javascript :: class constructor syntax 
Javascript :: react show view based on role permission 
Javascript :: 30 mins 24 hours jquery loop 
Javascript :: slideshow react npm 
Javascript :: Highlight current nav link in react 
Javascript :: vue js data bind 
Javascript :: * ws in ./node_modules/puppeteer/lib/WebSocketTransport.js 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =