Google Shared Locations
Google Shared Locations provides a NodeJS interface to reading location information from people that share theirs with you. It is a workaround for official Google maps API for Shared Locations that does not exist.
Warning: As there is no official API, you can not use the API key. You must enter your main Google Account login, so be careful.
npm install google-location-sharing
yarn add google-location-sharing
Minimal example of usage (asynchronous call using Promise):
const gls = ;glsgoogleEmail = 'googleAccountEmail@gmail.com';glsgooglePassword = 'googleAccountPassword';gls;
Usage in a synchronous process:
locations = await gls.getLocations();
For a complete example of how to use this library, save and re-load cookies, see file
check.js in the
Array of objects with localization data.
id: "5481211564887755445"name: "Bob Jones"shortname: "Bob"visible: true // whether this user is displayed on google mapslat: 40682825 // latitude: north–south positionlng: -7393883 // longitude: east–west positionlocationname: "Brooklyn, NY 11206, USA"photoURL: ""battery: 25 // shared device battery statuslastupdateepoch: 1531057287792 // last detection timestampid: "456458852120012354697"name: "Eric Draven"shortname: "Eric"visible: truelat: 47657484lng: -122329041locationname: "4100-4198 Eastern Ave, Seattle, WA 98103, USA"photoURL: ""battery: 78lastupdateepoch: 1531054742192
Supported only with 'Cell phone verification' (not google authenticator).
If 2FA is detected, this code return error
'Cell phone verification'.
Then you get confirmation on your phone. After google ask you if you want to allow a new account login and you agree with that, you can call
gls.getLocations() again and the code will continue running with the original credentials set in previous step. For full example see
check.js file in
Google default returns the location of the people who share it with the account owner. Location of account owner is not set in the same part of location file. Extract from this file does not contain information about the account owner. You can customize this owner informations and set it to output array before call
gls.getLocations() like this:
glsownerId = '0123456789';glsownerName = 'John Doe';glsownerShortname = 'John';glsownerPhotoUrl = '';
These data become part of credentials, so if you store credentials from
gls.credentials like (see example in
storage.setItem('credentials_storage_key', gls.credentials) you can load it by
gls.credentials = credentials; then with all data for account owner.
On first run, a full login will be performed to establish the cookie.
After this, subsequent calls to
getLocations() (within the same run - so, this is not persistent) will use the cookie.
You can save and load cookies in your own code to be persistent, an example of how to do it is in the
Unit and integration testing
npm run test
Functional test for real use case
To test this library with real account you need to call this script from project root directory:
node ./tests/check.js <googleAccountEmail> [googleAccountPassword] [--options]
This command runs authentication, to obtain shared location. It returns time logs, cookies and shared locations for user on input. If you use
--save parameter, you can next time use
--load and reduce time for get location data (skip authentication).
2.0 breaking changes
- Code is full async.
- Output attributes clean up. New
battery(battery status of device which share location) and
visible(if user shared location is not too old and it should be displayed on Google maps) attributes. Removed
longitude(duplicates). You can calculate original
new Date(new Date(0).setUTCSeconds(data.toString().substring(0,10))).
- Updated for 2FA. After confirmation on your phone you can continue and get shared location data. See more in 2FA section.
- Credentials object modification. Password for google account is write only.