Skip to content

Instantly share code, notes, and snippets.

@davetapley
Created April 16, 2013 17:29
Show Gist options
  • Save davetapley/5397829 to your computer and use it in GitHub Desktop.
Save davetapley/5397829 to your computer and use it in GitHub Desktop.
Pull entire Latitude history for a user
// https://developers.google.com/latitude/v1/using#ListingHistory
var minTimeMs = 0, // Earliest location to pull, 1st Jan 1070 seems far back enough.
maxTimeMs = Date.new().getTime(), // Latest location to pull, now.
lastResponse = [];
while {
// it is assumed this returns a max of 1000 locations in reverse chronological order,
// most recent location before maxTime first,
// then 999 more locations going back in time.
googleclient.getLocationHistory(minTimeMs, maxTimeMs, function(err, response) {
if(err) {
lastResponse = [];
} else {
lastResponse = response;
}
});
// this handles duplicates, but it shouldn't get any if the API is behaving
storeLocations(lastResponse);
// terminate when we've got all their history
if (lastResponse.length == 0) {
break;
}
// now we're only interested in locations prior to the 1000 we just got
maxTime = lastResponse[0].timestampMs;
}
@davetapley
Copy link
Author

This will fail miserably because getLocationHistory is asynchronous, but how best should I express it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment