js如何获取GPS的坐标
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)
}