• html5获取当前的位置..在地图中


    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <p id="demo">点击这个按钮,获得您的位置</p>
    <button onclick="getLocation()">试一下</button>
    <div id="mapholder"></div>
    <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)
      {
      lat=position.coords.latitude;
      lon=position.coords.longitude;
      latlon=new google.maps.LatLng(lat, lon)
      mapholder=document.getElementById('mapholder')
      mapholder.style.height='250px';
      mapholder.style.width='500px';
     
      var myOptions={
      center:latlon,zoom:14,
      mapTypeId:google.maps.MapTypeId.ROADMAP,
      mapTypeControl:false,
      navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL}
      };
      var map=new google.maps.Map(document.getElementById("mapholder"),myOptions);
      var marker=new google.maps.Marker({position:latlon,map:map,title:"You are here!"});
      }
    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>
  • 相关阅读:
    JS 中如何判断字符串类型的数字
    使用script的src实现跨域和类似ajax效果
    JS跨域(ajax跨域、iframe跨域)解决方法及原理详解(jsonp)
    IOS上架截屏 屏幕快照
    IOS 证书失效
    80端口占用
    PHP环境 PDOException PDOException: could not find driver
    分布式部署
    AES 加密算法 跨语言
    AES 加密填充 PKCS #7
  • 原文地址:https://www.cnblogs.com/tian-sun/p/7404166.html
Copyright © 2020-2023  润新知