【问题标题】:Method to find current location without using google map api不使用谷歌地图api查找当前位置的方法
【发布时间】:2013-03-01 07:14:03
【问题描述】:

Google map api 的当前位置在某些环境中不起作用。我们可以使用其他任何服务来获取当前地理位置

【问题讨论】:

    标签: codeigniter currentlocation


    【解决方案1】:

    您可以为此使用 Html5。

    请看下面的例子:

    JS)

    <script type="text/javascript">
    function showLocation(position) {
      var latitude = position.coords.latitude;
      var longitude = position.coords.longitude;
      alert("Latitude : " + latitude + " Longitude: " + longitude);
    }
    
    function errorHandler(err) {
      if(err.code == 1) {
        alert("Error: Access is denied!");
      }else if( err.code == 2) {
        alert("Error: Position is unavailable!");
      }
    }
    function getLocation(){
    
       if(navigator.geolocation){
          // timeout at 60000 milliseconds (60 seconds)
          var options = {timeout:60000};
          navigator.geolocation.getCurrentPosition(showLocation, 
                                                   errorHandler,
                                                   options);
       }else{
          alert("Sorry, browser does not support geolocation!");
       }
    }
    </script>
    

    调用函数的HTML按钮

       <form>
         <input type="button" onclick="getLocation();" value="Get Location"/>
       </form>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-07
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多