Loading

HTML5获取当前的经纬度坐标

使用IE10可以查看出结果;chrome和ff都没有正确显示;

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>jingweidu</title>
    <script>
    window.addEventListener('load', function() {
        if (navigator.geolocation) {
            navigator.geolocation.watchPosition(update);
        }
    }, false);

    function update(position) {
        var lat = position.coords.latitude;
        var lng = position.coords.longitude;
        document.write('维度:' + lat + ', 经度:' + lng);
    }
    </script>
</head>

<body>

</body>

</html>

 

posted @ 2015-07-21 08:50  stono  阅读(6253)  评论(0编辑  收藏  举报