Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML DOM Geolocation coords.speed Property

  • Last Updated : 15 Nov, 2021

In this article, we will discuss the Geolocation speed property. Geolocation in HTML is used to get the geographical position of a user.

The coords.speed property is used to return the speed in the location in meters per second (mps).

Syntax:

coords.speed

Example: The following HTML code will return the speed.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width,initial-scale=1">
</head>
  
<body>
    <h2 style="color:green">GeeksforGeeks</h2>
    <p><b> Displaying Speed in MPS</b></p>
  
    <button onclick="getlocation()"> Click Me </button>
    <p id="paraID"></p>
  
    
    <script>
      var variable1 = document.getElementById("paraID");
  
      function getlocation() {
          navigator.geolocation.getCurrentPosition(showLoc);
      }
  
      function showLoc(pos) {
          variable1.innerHTML = "Speed: " 
            + pos.coords.speed;
      }
    </script>
</body>
  
</html>

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!