获取手机当前位置经纬度 - 一键定位
<!DOCTYPE html>
<html>
<head>
<title>获取手机当前位置经纬度 - 一键定位</title>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
alert("Geolocation is not supported by this browser.");
}
}
<pre><code> function showPosition(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("Latitude: " + latitude + "\nLongitude: " + longitude);
}
</script>
</code></pre>
</head>
<body>
<button onclick="getLocation()">获取当前位置经纬度</button>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/qFER 著作权归作者所有。请勿转载和采集!