JSFiddle - React, Tailwind, and code Playground

by ojtramp

JavaScript

var options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
};


function success(pos) {
  var crd = pos.coords;

  console.log('Your current position is:');
  console.log(`Latitude : ${crd.latitude}`);
  console.log(`Longitude: ${crd.longitude}`);
  console.log(`More or less ${crd.accuracy} meters.`);

}

function error(err) {

  // Use err.message as the err.code is shared between multiple reasons for failure
  if (err.message == "User denied Geolocation") {
  
    alert("User refused to share their location");
    // Add your code here
    
  } 

  console.warn(`ERROR(${err.code}): ${err.message}`);


}

navigator.geolocation.getCurrentPosition(success, error, options);