geolocation——定位PC——IP地址精度比较低IP库Chrome -> Google手机——GPSwindow.navigator.geolocation单次 getCurrentPosition(成功, 失败, 参数)enableHighAccuracy 高精度模式——更慢、更费电timeout 超时maximumAge 缓存时间结果:latitude/longitude 纬度/经度altitude 海拔高度accuracy 精确度altitudeAccuracy 高度精确度heading 朝向speed 速度监听 watchPosition(成功, 失败, 参数)
demo;
<!DOCTYPE html>
<html><head><meta charset="utf-8"><script type="text/javascript">window.οnlοad=function (){let oBtn=document.getElementById('btn1');oBtn.οnclick=function (){if(window.navigator.geolocation){navigator.geolocation.getCurrentPosition(res=>{alert('成功');}, err=>{alert('失败');}, {/*enableHighAccuracy //高精度模式timeout //超时时间maximumAge //缓存*/});}else{alert('你的浏览器不支持定位');}};};</script><title></title></head><body><input type="button" name="" value="定位" id="btn1"></body>
</html>