<!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(&quot;Latitude: &quot; + latitude + &quot;\nLongitude: &quot; + longitude);
    }
&lt;/script&gt;
</code></pre>
</head>
<body>
    <button onclick="getLocation()">获取当前位置经纬度</button>
</body>
</html>
获取手机当前位置经纬度 - 一键定位

原文地址: https://www.cveoy.top/t/topic/qFER 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录