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.
Does anyone know how to force Google Chrome to use a Lat and Long that I provide as the location?
Manually change your location in ChromeHit Esc, then click the Console menu (three dots to the left of Console in the lower portion of the screen). Select Sensors and change the Geolocation dropdown to Custom location… Enter any latitude and longitude you want.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With