NonplayerCharacter

JS | Browsers geolocation API

Jan 13th, 2020
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   function success(position) {
  2.     const latitude  = position.coords.latitude;
  3.     const longitude = position.coords.longitude;
  4.     console.log(latitude+', '+longitude);
  5.   }
  6.   function error() {
  7.     console.log('Unable to retrieve your location');
  8.   }
  9.   if (!navigator.geolocation) {
  10.     console.log('Geolocation is not supported by your browser');
  11.   } else {
  12.     navigator.geolocation.getCurrentPosition(success, error);
  13.   }
  14. // result:
  15. > 12.12345667, 12.34567890
Advertisement
Add Comment
Please, Sign In to add comment