本文讲解的版本信息如下,如果使用的版本和讲解的版本差距过大,可能会有不同的地方。
系统 | Window 11 |
Chrome 版本 | 125.0.6422.142(正式版本) |
dev tools 语言 | 英文 |
关于Sensors
当针对移动设备进行开发时,会有一些诸如获取地理位置,角度、尺寸、方向等操作。我们可以使用Sensors来调试。
打开Sensors面板
devtools > More tools > Sensors打开传感器
使用传感器工具替代地理位置
Location区域功能总体如下,使用此区域功能可以模拟地理定位坐标以测试地理定位替换值。
我们现在使用geolocation API获取经纬度信息
// 监控
navigator.geolocation.watchPosition(position => {
const { latitude, longitude } = position.coords;
document.getElementById('latitude').innerText = latitude;
document.getElementById('longitude').innerText = longitude;
document.getElementById('timeZone').innerText = Intl.DateTimeFormat().resolvedOptions().timeZone