Extract data from Google Location History

633 Views Asked by At

I'm trying to produce some documentation for my tax return and I would need to count how many days I stayed in a country.

Google Location History offers the possibility to download the data and with the aid of some tools, it's possible to extract some meaningful data.

I saw some tools that mainly plotted charts and heatmaps, often made through analysis with R.

How to map your Google location history with R

Would it be possible to:

  • Count X amount of days spent in a country (e.g. X days in UK, Y days in Germany, Z days in U.S.A.)
2

There are 2 best solutions below

0
On

Using the geonames package you can lookup a country code from lat-long:

> require(geonames)
> options(geonamesUsername="get_a_username_from_geonames.org")
> GNcountryCode(lng=0.2,lat=52.03)
$languages
[1] "en-GB,cy-GB,gd"

$distance
[1] "0"

$countryCode
[1] "GB"

$countryName
[1] "United Kingdom of Great Britain and Northern Ireland"

I would go over your locations and compute the country code, and construct a data frame of data, country code, then use tools in the dplyr package to count the number of unique days per country. Not sure how to deal with part-days though...

0
On
library("devtools")  # this is needed to install the package from Github

install_github("corynissen/GoogleLocationHistory")

library("GoogleLocationHistory")

sess <- login(username="[email protected]", password="mypassword")

df <- location_history(session=sess, date="2014-06-29")