jQuery Mobile + HTML5 擷取地理位置資訊

來源:互聯網
上載者:User

標籤:show   jquery   tin   cell   void   cal   callback   blank   -o   

 

 這個代碼也非常簡單,核心是HTML5中GeoLocation API,函數原型定義如下: 
void getCurrentPosition(in PositionCallback successCallback,                           in optional PositionErrorCallback errorCallback,                           in optional PositionOptions options);
  標籤: jQuery Mobile 程式碼片段(3)[全屏查看所有代碼]1. [代碼][JavaScript]代碼     ?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 <!DOCTYPE html><html>    <head>        <meta charset="utf-8" />        <meta name="viewport" content="width = device-width; initial-scale=1">        <title>GeoLocation API示範程式</title>        <link rel="stylesheet" href="jquery.mobile.css" />        <script src="jquery.min.js"></script>        <script src="jquery.mobile.min.js"></script>                 <script type="text/javascript">      function startgps()      {        var gps = navigator.geolocation;        if (gps)        {            gps.getCurrentPosition(showgps,                                 function(error)                                 {                                        alert("Got an error, code: " + error.code + " message: "+ error.message);                                 },                                 {maximumAge: 10000}); // 這裡設定逾時為10000毫秒,即10秒                }                else                {                    showgps();                }            }                   function showgps(position)      {                if (position)                {                    var latitude = position.coords.latitude;                    var longitude = position.coords.longitude;                    alert("latitude: " + latitude + "\r\n longitude: "+ longitude);                }                else                    alert("position is null");      }  </script>             </head>     <body>        <section class="ui-page ui-body-c ui-page-active" data-url="page1" id="page1" data-role="page">            <header role="banner"    class="ui-bar-a ui-header" data-role="header">                <h1 aria-level="1" role="heading"    tabindex="0" class="ui-title">GeoLocation API Demo</h1>            </header>            <div role="main" data-role="content" class="ui-content">                <input type="button" value="我的位置" onclick="startgps()"/>            </div>            <footer role="contentinfo" class="ui-bar-a ui-footer" data-role="footer">                <h1 aria-level="1" role="heading"    tabindex="0" class="ui-title">Allan Yan</h1>            </footer>        </section></html>
2. [圖片] IMG_0073.PNG    3. [圖片] IMG_0074.PNG    舉報

jQuery Mobile + HTML5 擷取地理位置資訊

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.