zoukankan      html  css  js  c++  java
  • H5 获取地理位置

    只能通过手机浏览器访问,并且用户必须允许访问才可以生效

    <!doctype html>
    <html>
      <head>
            <title>Mobile Cookbook</title>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
      </head>
      <body>
        <header>
        </header>
            <div id="main">
                <div id="someElm">
                </div>
            </div>
        <footer>
        </footer>
        <script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
        <script>
        function getLocation() {
        navigator.geolocation.getCurrentPosition(showInfo);
      }
      function showInfo(position) {
          console.log(position);
        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;
        var accuracy = position.coords.accuracy;
        $('#someElm').html('latitude: '+latitude+'<br />longitude: '+longitude+'<br />accuracy: '+accuracy);
      }
      getLocation();
        </script>
        </body>
    </html>

  • 相关阅读:
    防御式编程
    Linux磁盘与文件系统管理
    更加抽象
    高质量的子程序
    Linux文件与目录管理
    抽象
    可以工作的类
    Linux的文件权限与目录配置
    条件、循环和其他语句
    软件构建中的设计
  • 原文地址:https://www.cnblogs.com/CyLee/p/6274776.html
Copyright © 2011-2022 走看看