zoukankan      html  css  js  c++  java
  • navigator.geolocation例子

    navigator.geolocation例子

      1. <html>  
      2.   
      3. <head>  
      4. <script type="text/javascript">  
      5. function getPositionSuccess(position){  
      6.     var lat = position.coords.latitude;  
      7.     var lng = position.coords.longitude;  
      8.     document.write("所在位置: 经度(" + lat + "),纬度(" + lng + ")");  
      9.     if(typeof position.address !== "undefined"){  
      10.         var country = position.address.country;  
      11.         var province = position.address.region;  
      12.         var city = position.address.city;  
      13.         document.write("<br />");  
      14.         document.write("您位于" + country + province + city);  
      15.     }  
      16. }  
      17. function getPositionError(error){  
      18.     switch(error.code){  
      19.         case error.TIMEOUT:  
      20.             alert("连接超时,请重试");  
      21.             break;  
      22.         case error.PERMISSION_DENIED:  
      23.             alert("您拒绝了使用位置共享服务,查询已取消");  
      24.             break;  
      25.         case error.POSITION_UNAVAILABLE:  
      26.             alert("亲爱的火星网友,非常抱歉,我们暂时无法为您所在的星球提供位置服务");  
      27.             break;  
      28.     }  
      29. }  
      30. </script>  
      31. </head>  
      32.   
      33. <body>  
      34.     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>  
      35.     <script type="text/javascript">  
      36.         if(navigator.geolocation){  
      37.             navigator.geolocation.getCurrentPosition(getPositionSuccess, getPositionError);  
      38.         }else{  
      39.             alert("您的浏览器不支持Geolocation!");  
      40.         }  
      41.     </script>  
      42. </body>  
      43.   
      44. </html

    转载:http://blog.csdn.net/gohome520/article/details/7338486

  • 相关阅读:
    python的Collections 模块
    python模块
    python类
    python异常
    python文件处理
    python函数
    python字符串
    python数据结构
    python循环
    下载Google Play外国区APP技巧
  • 原文地址:https://www.cnblogs.com/wluomo/p/4058920.html
Copyright © 2011-2022 走看看