Ex No: 14 RETURN USER LOCATION
Aim: To write a JavaScript code to return the latitude and logitude of the users current location.
Algorithm
Step1: Create a folder “Ex14” to place the HTML files.
Step2: Create HTML file “index.html”.
Step3: Use navigator objects geolocation property to get the current position of the user.
Step4: Display the Latitude and Logitude of the users current location.
Source Code

index.html


<!DOCTYPE html>
<html>
   <head>
      <title>Location</title>   
   <style>
     header {
      text-align:center;
      height: 100px;
      background-color: MediumPurple;
      padding: 10px;
      border-radius: 10px 10px 0px 0px;
     }
     footer {
      text-align:center;
      font-size: 12px;
      height: 50px;
      line-height: 50px;
      background-color: MediumPurple;
      padding: 10px;
      border-radius: 10px;
     }
   </style>
   </head>
   <body>      
      <header>
         <h1>Geo Location</h1>
      </header>   
      <hr>
      <input type="button" value="Get Location" onclick="getLocation()">
      <h3 id="locData"></h3>
      <footer>
         Developed by K Anbarasan
      </footer>      
      <script type="text/javascript">
         const out = document.getElementById("locData");
         function getLocation() 
         {
          if (navigator.geolocation) 
          {
            navigator.geolocation.getCurrentPosition(latandlong);
          } 
          else 
          {
            out.innerHTML = "Geolocation is not supported by this browser.";
          }
         }
		 
         function latandlong(position) 
         {
          out.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
         }
      </script>
   </body>
</html>
Result: Thus JavaScript code to return the latitude and logitude of the users current location.