Skip to content

Instantly share code, notes, and snippets.

@dwaps
Created December 7, 2019 08:43
Show Gist options
  • Save dwaps/28528ba9a0aa7d59a3be01b76d9fb8ed to your computer and use it in GitHub Desktop.
Save dwaps/28528ba9a0aa7d59a3be01b76d9fb8ed to your computer and use it in GitHub Desktop.
HTML5 API: Geolocation --> getCurrentPosition()
if ('geolocation' in navigator) {
const { geolocation } = navigator;
geolocation.getCurrentPosition(success, error);
function success(position) {
const { coords } = position;
const p = document.querySelector('p');
p.innerHTML = `
<strong>LAT:</strong> ${coords.latitude}<br>
<strong>LNG:</strong> ${coords.longitude}
`;
}
function error(error) {
console.error(error);
}
}
// Generate a self signed certificate
// openssl req -nodes -new -x509 -keyout dwaps.key -out dwaps.cert
const app = require('express')();
const { readFileSync } = require('fs');
const key = readFileSync('dwaps.key');
const cert = readFileSync('dwaps.cert');
require('https').createServer(
{ key, cert },
app.get(
'/',
(req, res) => {
const scriptGeolocation = readFileSync('geolocation.js');
res.end(`<p></p><script>${String(scriptGeolocation)}</script>`);
})
).listen(8081);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment