SOURCE

function updateStatus(message) {
  document.getElementById("status").innerHTML = message;
}

function endRequest() {
  updateStatus("Done.");
}

function updateLocation(position) {
  endRequest();
  // 处理位置数据
}

function handleLocationError(error) {
  endRequest();
  // 处理错误
}

navigator.geolocation.getCurrentPosition(updateLocation, handleLocationError, {timeout:10000});
// 超过时间为10s

updateStatus("Requesting location data...");
function updateStatus(message) {
  document.getElementById("status").innerHTML = message;
}

navigator.geolocation.getCurrentPosition(updateLocation, handleLocationError, {timeout:10000});
// 超过时间为10s

updateStatus("Requesting locationbar data...");
function endRequest() {
  updateStatus("Done.");
}
function updateLocation(position) {
  endRequest();
  
  // 处理位置数据
}
var map = new google.maps.Map(document.getElementById("map"));
function updateLocation(position) {
  // 将位置信息传递给Google Map,并将其居中
  map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
}
navigator.geolocation.getCurrrentPosition(updateLocation, handleLocation);
console 命令行工具 X clear

                    
>
console