Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

html api

const myElement = document.getElementById("demo");

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    myElement.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  myElement.innerHTML = "Latitude: " + position.coords.latitude +
  "<br>Longitude: " + position.coords.longitude;
}
 
PREVIOUS NEXT
Tagged: #html #api
ADD COMMENT
Topic
Name
8+8 =