Created
December 7, 2019 08:43
-
-
Save dwaps/28528ba9a0aa7d59a3be01b76d9fb8ed to your computer and use it in GitHub Desktop.
HTML5 API: Geolocation --> getCurrentPosition()
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
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); | |
} | |
} |
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
// 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