<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>获取经纬度</title>
</head>
<body>
<button id="button">获取经纬度</button>
<script>
let button = document.getElementById('button')
button.onclick = function (evt) {
navigator.geolocation.getCurrentPosition(function success(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
let r = document.createTextNode(`Latitude${latitude},Longitude${longitude}`)
document.body.appendChild(r)
});
}
</script>
</body>
</html>
转载请注明:有爱前端 » 获取经纬度