js如何获取GPS的坐标

2025-10-27 06:42:22

1、function getLocation(){      

    if(navigator.geolocation){       

     //判断是否有这个对象           

    navigator.geolocation.getCurrentPosition(function(pos){          

         console.log("经:"+pos.coords.longitude+  "纬:"+

         pos.coords.latitude)           

 })       

    }else{    

        console.log("当前不支持 ")       

     }   

 }

2、function getLocation(){       

   var options={          

            enableHighAccuracy:true,          

            maximumAge:1000      

   }       

   if(navigator.geolocation){          

      //支持geolocation           

     // alert("支持geolocation");         

   navigator.geolocation.getCurrentPosition(onSuccess,onError,options);          

}else{         

   //不支持geolocation            

  alert("不支持geolocation");      

  }  

}

3、function onSuccess(pos){       

    console.log("经:"+pos.coords.longitude+    

            "纬:"+pos.coords.latitude) 

 }

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢