jquery mobile 如何获取触摸的坐标

2025-03-31 01:14:07
推荐回答(3个)
回答1:

jquery mobile中获取触摸坐标的方法:

思路:利用jquery.mobile.js(下载)获取GPS设备的经纬度信息,然后显示输出在sogou地图上。 

1.加载jquery.min.js
2.加载jquery.mobile.min.js
3.var gps = navigator.geolocation;调用GPS


    
        
        手机GPS定位获取
        
        
        
        
            function initialize(GX,GY) {
             
                var map = new sogou.maps.Map(document.getElementById("map_canvas"), {
                    zoom: 15, //放大级别
                    center: new sogou.maps.LatLng(GX,GY),//设置中心点
                    mapTypeId: sogou.maps.MapTypeId.ROADMAP
                });
                 
                var myLatlng = new sogou.maps.LatLng(GX,GY);
                var marker1=new sogou.maps.Marker({
                    position: myLatlng, 
                    map: map,
                    title:"经纬度坐标:"+myLatlng,
                    label:{visible:true,align:"TOP"}
                });
            }
             
            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毫秒
                    ); 
                }else{
                    showgps();
                }
            }
                  
            function showgps(position){
                if (position)       {
                    var latitude = position.coords.latitude;
                    var longitude = position.coords.longitude;
                    initialize(latitude,longitude);//调用Sogou地图显示坐标
                }else{
                    alert("position is null");
                }
            }
             
        
          
            body{height:100%;margin:0px;padding:0px}
            #map_canvas{height:100%;height:500px;}
          
    
 
    
        

    

回答2:

会有一个相应的鼠标事件,这个 MouseEvent 中会有当时的像素坐标的。

回答3:

function(event){

var touch = event.touches[0];
touch.pageX;//触摸的x坐标点
touch.pageY;//触摸的Y坐标点
}

相关问答