Geolocation
How do I make an geolocation?
How to use navigator.geolocation to get the user's current latitude and longitude.. What is a geolocation? How do you make a geolocation? This script and codes were developed by Mobile Application Design-Development on 10 August 2022, Wednesday.
Geolocation - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Geolocation</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="output">
</div>
<p><a href="">MDN Geolocation Reference</a></p>
<p>This page must run under https to work</p> <script src="js/index.js"></script>
</body>
</html>
Geolocation - Script Codes CSS Codes
div, p{ font-size: 24px; line-height: 1.6; padding: 0.5rem 2rem;
}
Geolocation - Script Codes JS Codes
document.addEventListener("DOMContentLoaded", getLocation);
document.body.addEventListener("click", getLocation);
function getLocation(){ if( navigator.geolocation ){ document.getElementById("output").innerHTML = ""; //code goes here to find position let to = 1000 * 30; //1000 times 30 = 30 seconds let max = 1000 * 60 * 60; //1000 * 60 * 60 = 1 hour var params = {enableHighAccuracy: false, timeout:to, maximumAge:max}; //enableHighAccuracy means try to use GPS and drain the battery //for improved accuracy within a few meters. //maximum age is how long to cache the location info //timeout is how long to wait for the network to respond after the user says ok navigator.geolocation.getCurrentPosition( reportPosition, gpsError, params ); //to continually check the position (in case it changes) use // navigator.geolocation.watchPosition( reportPosition, gpsError, params) }else{ //browser does not support geolocation api alert("Sorry, but your browser does not support location based awesomeness.") }
};
function reportPosition( position ){ var output = document.querySelector("#output"); output.innerHTML += "Latitude: " + position.coords.latitude + "°<br/>" + "Longitude: " + position.coords.longitude + "°<br/>" + "Accuracy: " + position.coords.accuracy + "m<br/>" + "Altitude: " + position.coords.altitude + " m<br/>" + "Heading: " + position.coords.heading + " °<br/>" + "Speed: " + position.coords.speed + " m/s<br/>" + "Timestamp: " + position.timestamp;
}
function gpsError( error ){ var errors = { 1: 'Sorry your browser did not have permissions to get your location.', 2: 'Unable to determine your location.', 3: 'Location request took too long.' }; // errors[1] alert("Error: " + errors[error.code] + "... " + error.message );
}
Developer | Mobile Application Design-Development |
Username | mad-d |
Uploaded | August 10, 2022 |
Rating | 3 |
Size | 2,429 Kb |
Views | 26,312 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Two-Column Form | 2,518 Kb |
HTML Modal Windows | 2,995 Kb |
Closure Failure | 1,933 Kb |
MAD9022 Refactoring Practice | 2,315 Kb |
SVG CSS ViewBox Demo | 2,176 Kb |
Sept 14 Demo | 1,227 Kb |
MAD9013 - Float Images with Content | 2,220 Kb |
Sept 29, 2017 complete | 2,972 Kb |
Mad9014 - objects and arrays | 2,606 Kb |
A Pen by Mobile Application Design-Development | 1,870 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Vanilla JS - A toggleClass function | Woodwork | 2,532 Kb |
Pure CSS Tooltips | Mobius1 | 2,271 Kb |
Import shader in three.js | Khangeldy | 2,636 Kb |
Search Box in Content Moves to Fixed Header | Chriscoyier | 2,768 Kb |
Atom | Bhlaird | 1,932 Kb |
Apex Calculator | Michaelwnelson | 2,370 Kb |
Horizontal Navigation with Floats | Gymratpacks | 5,403 Kb |
CSS Variables | Jdsteinbach | 4,759 Kb |
Mega menu | DimaZubkov | 5,066 Kb |
Improved Page Flipping Effect | Usaphp | 5,201 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!