How can I set my latitude and longitude for debugging the Geolocation API with Google Chrome?(如何设置我的纬度和经度以使用 Google Chrome 调试 Geolocation API?)
问题描述
对于我的开发系统,我希望能够在 Chrome 中设置地理位置(纬度、经度),这样当我进行测试时,浏览器会认为我在位置 X,而实际上我可能在位置是的.
For my development system I'd like to be able to set the Geolocation (Lat, Long) in Chrome so that when I'm doing the testing the browser thinks I'm at location X when I really might be at location Y.
有谁知道如何强制 Google Chrome 使用我提供的经纬度作为位置?
Does anyone know how to force Google Chrome to use a Lat and Long that I provide as the location?
推荐答案
如果你说的是 Geolocation API,你可以重写这个函数:
If you're talking about the Geolocation API, you can override the function:
navigator.geolocation.getCurrentPosition = function(success, failure) {
success({ coords: {
latitude: 30,
longitude: -105,
}, timestamp: Date.now() });
}
所以当一个库调用 navigator.geolocation.getCurrentPosition
函数时,您指定的坐标将被返回.
So when a library calls into the navigator.geolocation.getCurrentPosition
function the coordinates you specify will be returned.
这篇关于如何设置我的纬度和经度以使用 Google Chrome 调试 Geolocation API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何设置我的纬度和经度以使用 Google Chrome 调试 Geolocation API?


基础教程推荐
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 直接将值设置为滑块 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01