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

10,125

Solution 1

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.

Solution 2

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

Solution 3

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/

Solution 4

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

Share:
10,125
Paul Mendoza
Author by

Paul Mendoza

Paul Mendoza has been developing software and web solutions for companies in Southern California. Paul is an expert in developing and architecting .NET solutions including the development of multiple online social networking applications, data analytics tools and working with customers to provide value driven results. Paul has given talks at conferences on topics ranging from SQL Server spatial data to how to write maintainable JavaScript.

Updated on June 05, 2022

Comments

  • Paul Mendoza
    Paul Mendoza almost 2 years

    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?

  • Shiv Singh
    Shiv Singh about 9 years
    Now that extension not available on store :(
  • Leif Gruenwoldt
    Leif Gruenwoldt about 7 years
    The menu names have changed a bit, but capability is still there. More tools -> Sensors -> Gelocation.