Search code examples
google-mapsgoogle-chromegoogle-maps-api-3geolocation

How do you fake your location with the google maps api


I am using the google maps API to gain a users location:

https://developers.google.com/maps/documentation/geolocation/intro

To test this I would like to fake the location however setting chromes geo location does not work as it seems to ignore this.


Solution

  • In the maps api itself you can't fake the position because it uses the geolocation functionality of your browser. If you want to fake your geolocation in Chrome you can do it like this:

    Press F12 to open the Developer Console. Change to the tab Console and open the menu with the 3 dots icon. Select More Tools --> Sensors and change the default value for the Geolocation from "No override" to a preset or enter own coordinates. Now reload the page and see how it works.

    I tested it right now on this Google Geolocation Tutorial page and inside an own application with Google maps. Good luck!

    It works the same way in:

    • Vivaldi
    • Opera (use CTRL + SHIFT + C instead of F12)

    Different for:

    • Firefox (I think you have to use an extension)
    • Internet Explorer 11 (F12, Tab Emulation, Geolocation --> on and enter lat and lon