如何设置我的经纬度来用Google Chrome调试Geolocation API? [英] How can I set my latitude and longitude for debugging the Geolocation API with Google Chrome?

查看:387
本文介绍了如何设置我的经纬度来用Google Chrome调试Geolocation API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的开发系统,我希望能够在Chrome中设置地理位置(Lat,Long),这样当我进行测试时,浏览器认为我处于位置X,当我真的可能在位置Y。

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆