Created
October 14, 2016 02:33
-
-
Save tcelestino/f0bcbfa3b49a73658c2171eb9e153c3c to your computer and use it in GitHub Desktop.
Geolocation callback example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Geolocation Example</title> | |
</head> | |
<body> | |
<script> | |
(function() { | |
var latLong = {}; // para funcionar como uma global no escopo. | |
const getLatLong = function() { | |
console.log(latLong); | |
} | |
const getPosition = function(position) { | |
latLong = { | |
lat: position.coords.latitude, | |
long: position.coords.longitude | |
} | |
getLatLong(); | |
} | |
const errorPosition = function(error) { | |
console.error(error); | |
} | |
if('geolocation' in navigator) { | |
let geo = navigator.geolocation; | |
geo.getCurrentPosition(getPosition, errorPosition); | |
} | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment