Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 826
Paul Mendoza Avatar asked Mar 31 '11 19:03

Paul Mendoza


People also ask

How do I manually use Chrome geolocation extension?

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.


2 Answers

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.

like image 156
Andy Edinborough Avatar answered Sep 21 '22 20:09

Andy Edinborough


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".

enter image description here

like image 36
Glen Little Avatar answered Sep 19 '22 20:09

Glen Little