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 :: Math prime js 
Javascript :: How to Keep the Current Tab Active on Page Reload 
Javascript :: convert month name to month number in js 
Javascript :: Finding the array element: 
Javascript :: check length of number javascript 
Javascript :: js switch case greater than 
Javascript :: if json then parse 
Javascript :: await set timeout 
Javascript :: replace all spaces with dash in javascript 
Javascript :: js check query string 
Javascript :: Jquery get value of dropdown selected 
Javascript :: match date regex 
Javascript :: regex for yyyy-mm-dd 
Javascript :: vue local storage delete 
Javascript :: javascript startswith 
Javascript :: build palindrome javascript 
Javascript :: Nazmul 
Javascript :: js get domain 
Javascript :: how to reset auto numeric js for input 
Javascript :: media query in react js 
Javascript :: react-native curved view 
Javascript :: prevent form from reloading with preventDefault 
Javascript :: hide cursor p5js 
Javascript :: jsconfig.json vue 
Javascript :: concurrently script 
Javascript :: option selected jquery 
Javascript :: javascript redirect another page 
Javascript :: how to use await to console 
Javascript :: sort multidimensional array javascript 
Javascript :: redirecting to a different route if user is logged in 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =