隐藏

javascript 怎么获得手机地理位置 比如经纬度

发布:2015/9/4 23:53:10作者:管理员 来源:本站 浏览次数:1561

<script>
    navigator.geolocation.getCurrentPosition( // 该函数有如下三个参数
        function(pos){ // 如果成果则执行该<a href="https://www.baidu.com/s?wd=%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YvP1IWmWw-nj04uAuWrH60IAYqnWm3PW64rj0d0AP8IA3qPjfsn1bkrjKxmLKz0ZP1TjYk0ZP1TjcqnfKdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPW6sPjbLnH0kPWnsnj61PjRz" target="_blank" class="baidu-highlight">回调函数</a>
            alert(
                '  经度:' + pos.coords.latitude +
                '  纬度:' + pos.coords.longitude +
                '  高度:' + pos.coords.altitude +
                '  精确度(经纬):' + pos.coords.accuracy +
                '  精确度(高度):' + pos.coords.altitudeAccuracy +
                '  速度:' + pos.coords.speed
            );
        }, function(err){ // 如果失败则执行该<a href="https://www.baidu.com/s?wd=%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YvP1IWmWw-nj04uAuWrH60IAYqnWm3PW64rj0d0AP8IA3qPjfsn1bkrjKxmLKz0ZP1TjYk0ZP1TjcqnfKdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPW6sPjbLnH0kPWnsnj61PjRz" target="_blank" class="baidu-highlight">回调函数</a>
            alert(err.message);
        }, { // 附带参数
            enableHighAccuracy: false// 提高精度(耗费资源)
            timeout: 3000, // 超过timeout则调用失败的<a href="https://www.baidu.com/s?wd=%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YvP1IWmWw-nj04uAuWrH60IAYqnWm3PW64rj0d0AP8IA3qPjfsn1bkrjKxmLKz0ZP1TjYk0ZP1TjcqnfKdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPW6sPjbLnH0kPWnsnj61PjRz" target="_blank" class="baidu-highlight">回调函数</a>
            maximumAge: 1000 // 获取到的地理信息的有效期,超过有效期则重新获取一次位置信息
        }
    );
</script>