Created
April 16, 2013 17:29
-
-
Save davetapley/5397829 to your computer and use it in GitHub Desktop.
Pull entire Latitude history for a user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will fail miserably because
getLocationHistory
is asynchronous, but how best should I express it?