📜  js 获取用户位置 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:23.992000             🧑  作者: Mango

代码示例1
var x = document.getElementById("demo");
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude +
  "
Longitude: " + position.coords.longitude; }