js实现获取手机gps经纬度位置和陀螺仪数据实现指南针和水平仪效果代码

代码语言:html

所属分类:其他

代码描述:js实现获取手机gps经纬度位置和陀螺仪数据实现指南针和水平仪效果代码,请在手机上预览。

代码标签: 指南针 陀螺仪 手机 位置 经纬度 水平仪

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <style>
        * {
            padding: 0px;
            margin: 0px;
            list-style: none;
        }

        :root,
        body {
            height: 100%;
        }

        body {
            height: 100%;
            display: flex;
            justify-content: center;
        }

        .show {
            height: 95%;
            width: 350px;
            transform: translate3D(0px, 20px, 0px);
        }

        .wrapper {
            position: relative;
            width: 700px;
            height: 100%;
            display: flex;
        }

        /* 第二页水平仪 */
        .wrapper .gradienter-out {
            position: relative;
            height: 100%;
            width: 350px;
        }

        .wrapper .gradienter-out span {
            position: absolute;
            left: calc(50% - 50px);
            top: calc(50% - 50px);
            height: 100px;
            width: 100px;
            border-radius: 50%;
           
        }

        .wrapper .gradienter-out span div {
            position: absolute;

            height: 50px;
            width: 100px;
            top: calc(50% - 25px);
            text-align: center;
            line-height: 50px;
            font-size: 30px;
            font-weight: bold;
            transform-origin: center center;
        }


        /* 第一页 */
        .box {
            position: relative;
            width: 350px;
            height: 100%;

        }

        /* 方向文字、经纬度 */
        .box .text {
            position: absolute;
            width: 350px;
            height: 120px;
            left: calc(50% - 175px);
            top: 20px;
            font-size: 13px;
            font-weight: bold;
        }

        .box .text .direction-angle {
            height: 50px;
            line-height: 50px;
            text-align: center;
            font-size: 30px;
            margin-bottom: 10px;
        }

        .box .text .latitude {

            float: left;
            margin-left: 50px;
            color: rgba(0, 0, 0, .5)
        }

        .box .text .longitude {
            float: right;
            margin-right: 50px;
            color: rgba(0, 0, 0, .5)
        }


        /* 指针 */
        .box .point {
            position: absolute;
            height: 25px;
            width: 2px;
            left: 50%;
            top: 165px;
            background-color: black;
            z-index: 10;
        }

        /* 表盘 */

        .box .dial {
            position: relative;
            height: 300px;
            width: 300px;
            top: 170px;
            left: calc(50% - 155px);

            transform-origin: 158px 111px;
        }

        /* 外圈表盘刻度 */

        .box .dial .scale {
            position: absolute;
            height: 300px;
            width: 300px;
            border-radius: 50%;
            transform-origin: 150px 150px;
            transform: translatez(0px) rotate(11deg);
        }

        /* 小刻度 */
        .box .dial .scale ul li {
            position: absolute;
            left: calc(50% - 1px);
            width: 2px;
            height: 10px;
            background-color: #ddd;
            transform-origin: center 110px;
        }

        /* 中刻度 */
        .box .dial .scale ul li:nth-of-type(5n) {
            height: 12px;
        }

        /* 大刻度 */
        .box .dial .scale ul li:nth-of-type(10n) {
            height: 15px;
            background-color: rgba(0, 0, 0, .5);
        }

        /* 数字和方向 */
        .box .dial .num ul li,
        .box .dial .num .direction {
            position: absolute;
            height: 25px;
            width: 34px;
            left: calc(50% - 10px);
            top: 20px;
            text-align: center;
            line-height: 25px;
            font-family: '宋体';
            font-weight: 500;
            font-size: 10px;
            transform-origin: center 90px;
        }

        .box .dial .num .direction {
            top: 55px;
            transform-origin: center 55px;
        }

        /* 红色小标记 */
        .dial .num .sign {
            position: absolute;
            left: calc(50% - 4px);
            top: 30px;
            border-top: 10px solid transparent;
            border-left: 10px solid transparent;
            border-right: 10px solid transparent;

            border-bottom: 10px solid red;
        }

        .dial .num .direction span {
            position: absolute;
            display: block;
            height: 100%;
            width: 100%;
            text-align: center;
            transform-origin: center;
        }

        .north {
            color: red;
        }

        .box .gradienter-in {
            position: relative;
            left: calc(50% - 10px);
            top: -6%;
            height: 30px;
            width: 30px;
            border-radius: 50%;
            box-sizing: border-box;
            transform-origin: center;
        }
        .note{
            text-align: center;
            margin-top: 50px;
            color: grey;
        }
    </style>
</head>

<body>
    <div class="show">
        <div class="wrapper">
            <div class="box">

                <div class="text">
                    <div class="direction-angle">西北 123°</div>
                    <div class="latitude">北纬 <span>123°5'23"</span></div>
                    <div class="longitude">东经 <span> 123°5'23"</span></div>
                </div>
                <!-- 指针 -->
                <div class="point"></div>

                <!-- 表盘 -->
                <div class="dial">

                    <!-- 刻度 -->
                    <div class="scale">
                        <ul>
                            <li>*180
                        </ul>
                    </div>

                    <!-- 数字 -->
                    <div class="num">
                        <ul>
                            <li>0</li>
                            <li>20</li>
                            <li>40</li>
                            <li>60</li>
                            <li>80</li>
                            <li>100</li>
                            <li>120</li>
                            <li>140</li>
                            <li>160</li>
                            <li>180</li>
                            <li>200</li>
                            <li>220</li>
                            <li>240</li>
                            <li>260</li>
                            <li>280</li>
                            <li>300</li>
                            <li>320</li>
                            <li>340</li>

                        </ul>
                        <div class="sign"></div>
                        <div class=" direction north"><span>北</span></div>
                        <div class=" direction east"><span>东</span></div>
                        <div class=" direction south"><span>南</span></div>
                        <div class=" direction western"><span>西</span></div>
                    </div>
                </div>
                <!-- 中心水平仪 -->
                <div class="grad.........完整代码请登录后点击上方下载按钮下载查看

网友评论0