jQuery Mobile + HTML5 获取地理位置信息

2021-05-23 02:29

阅读:415

YPE html>

标签: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]代码     

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    
         "utf-8" />
         "viewport" content="width = device-width; initial-scale=1">
        GeoLocation API演示程序
         "stylesheet" href="jquery.mobile.css" />
        >
        >
         
        >
      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");
      }
  
         
    
 
    
        
class="ui-page ui-body-c ui-page-active" data-url="page1" id="page1" data-role="page">
            
"banner"    class="ui-bar-a ui-header" data-role="header">
                

"1" role="heading"    tabindex="0" class="ui-title">GeoLocation API Demo

            
            
"main" data-role="content" class="ui-content">
                "button" value="我的位置" onclick="startgps()"/>
            
            
"contentinfo" class="ui-bar-a ui-footer" data-role="footer">
                

"1" role="heading"    tabindex="0" class="ui-title">Allan Yan

            
        

2. [图片] IMG_0073.PNG    

技术分享

3. [图片] IMG_0074.PNG    

技术分享
举报

jQuery Mobile + HTML5 获取地理位置信息

标签:show   jquery   tin   cell   void   cal   callback   blank   -o   

原文地址:http://www.cnblogs.com/xzzzys/p/7687615.html


评论


亲,登录后才可以留言!