HTML DOM Geolocation coords.speed Property (original) (raw)

Last Updated : 1 Jun, 2022

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 `

GeeksforGeeks

Displaying Speed in MPS

<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>

`

Output:

Supported Browsers: