zoukankan      html  css  js  c++  java
  • html5获取经纬度

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <p id="demo">点击这个按钮,获得您的坐标:</p>
    <button onclick="getLocation()">试一下</button>
    <script>
    var x=document.getElementById("demo");
    function getLocation()
      {
      if (navigator.geolocation)
        {
        navigator.geolocation.getCurrentPosition(showPosition,showError);
        }
      else{x.innerHTML="Geolocation is not supported by this browser.";}
      }
    function showPosition(position)
      {
      x.innerHTML="Latitude: " + position.coords.latitude +
      "<br />Longitude: " + position.coords.longitude;
      }
    function showError(error)
      {
      switch(error.code)
        {
        case error.PERMISSION_DENIED:
          x.innerHTML="User denied the request for Geolocation."
          break;
        case error.POSITION_UNAVAILABLE:
          x.innerHTML="Location information is unavailable."
          break;
        case error.TIMEOUT:
          x.innerHTML="The request to get user location timed out."
          break;
        case error.UNKNOWN_ERROR:
          x.innerHTML="An unknown error occurred."
          break;
        }
      }
    </script>
    </body>
    </html>
  • 相关阅读:
    Linux命令比较文件内容
    Linux命令jobs小记
    权限控制框架
    Log4j2源码分析系列:(一)配置加载
    Callable和Supplier的区别
    排序算法之归并排序
    Spring boot整合Mybatis
    排序算法之堆排序
    排序算法之希尔排序
    排序算法之快速排序
  • 原文地址:https://www.cnblogs.com/tian-sun/p/7404171.html
Copyright © 2011-2022 走看看