Skip to content

Instantly share code, notes, and snippets.

@tcelestino
Created October 14, 2016 02:33
Show Gist options
  • Save tcelestino/f0bcbfa3b49a73658c2171eb9e153c3c to your computer and use it in GitHub Desktop.
Save tcelestino/f0bcbfa3b49a73658c2171eb9e153c3c to your computer and use it in GitHub Desktop.
Geolocation callback example
<!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