location nearby html

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Reports</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="google" value="notranslate" />
        <meta name="application-name" content="GeoLocator" />
        <meta name="description" content="HTML5's approach to email" />
        <meta name="application-url" content="https://developer.mozilla.org" />
        <meta name="google" content="notranslate" />
        <!--
        <link rel="canonical" href="https://mail.google.com/mail/" />
        <link rel="shortcut icon" href="https://ssl.gstatic.com/ui/v1/icons/mail/images/favicon2.ico" type="image/x-icon" />
        <link rel="alternate" type="application/atom+xml" title="Gmail Atom Feed" href="feed/atom" />
            -->
        <script type="text/javascript">
            // <![CDATA[
            var options = {
                enableHighAccuracy: true,
                timeout: 5000,
                maximumAge: 0
            };


            var x = null;

            function success(position) {
                var lat = position.coords.latitude;
                var lon = position.coords.longitude;
                var accuracyInMeters = position.coords.accuracy;


                x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
            }


            function error(err)
            {
                console.warn('ERROR(' + err.code + '): ' + err.message);
                x.innerHTML = '<span style="color: red;">No fix on location</span>';
            }

            function getLocation() {
                if (navigator.geolocation) {
                    // https://developer.mozilla.org/en-US/docs/Web/API/Geolocation.getCurrentPosition
                    // First of all, realise that the default timeout for getCurrentPosition is infinite(!). 
                    // That means that your error handler will never be called if getCurrentPosition hangs somewhere on the back end.

                    navigator.geolocation.getCurrentPosition(success, error, options); // Error and optios can be omitted
                } else {
                    alert("not supported")
                    x.innerHTML = "Geolocation is not supported by this browser.";
                }

            }





            document.addEventListener('DOMContentLoaded', function ()
            {
                x = document.getElementById("demo");
                /*fun code to run*/
                getLocation();
            })




            // ]]>
        </script>


        <style type="text/css" media="all">
            html, body {
                width: 100%;
                height: 100%;
                margin: 0px;
                padding: 0px;
            }

        </style>


    </head>
    <body>
        <div id="demo"></div>

    </body>
</html>

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source