How can I set my latitude and longitude for debugging the Geolocation API with Google Chrome?

若如初见. 提交于 2019-11-28 07:40:26

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() }); 
} 

So when a library calls into the navigator.geolocation.getCurrentPosition function the coordinates you specify will be returned.

In Chrome today (version 42), open Developer Tools, click the "Toggle Device Icon", then in the "Emulation" drawer, chose "Sensors". There, you can Emulate geolocation coordinates and even "Emulate position unknown".

You can now use the manual geolocation chrome extension to set your location manually.

A little late on the answer, but in Chrome you can open the Developer Tools (F12 or Ctrl + Shift + I). In the lower right hand open the 'Settings' gear and switch to the 'Overrides' tab. There is a checkbox labeled 'Override Geolocation'. Check this box and enter in what ever geolocation that you want the site to think you are at.

In case I haven't explained it clearly enough, here is a good article that goes over it with screenshots and what not: http://www.labnol.org/internet/geo-location/27878/

I am unaware of a way to do it in Chrome but you can do it in Firefox; this blog post will tell you how.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!