Untitled
unknown
plain_text
3 years ago
1.5 kB
5
Indexable
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <button id="find-me">Show my location</button><br /> <p id="status"></p> <iframe id="map-link" target="_blank"></iframe> <script> function geoFindMe() { const status = document.querySelector('#status'); const mapLink = document.querySelector('#map-link'); mapLink.src = ''; mapLink.textContent = ''; function success(position) { const latitude = position.coords.latitude; const longitude = position.coords.longitude; status.textContent = ''; mapLink.src = `https://www.openstreetmap.org/#map=18/${latitude}/${longitude}`; mapLink.textContent = `Latitude: ${latitude} °, Longitude: ${longitude} °`; } function error() { status.textContent = 'Unable to retrieve your location'; } if (!navigator.geolocation) { status.textContent = 'Geolocation is not supported by your browser'; } else { status.textContent = 'Locating…'; navigator.geolocation.getCurrentPosition(success, error); } } document.querySelector('#find-me').addEventListener('click', geoFindMe); </script> </body> </html>
Editor is loading...