#data from https://maps.google.co.uk/locationhistory/b/0/?hl=en-GB
#google location history
#create archive here from https://www.google.com/settings/takeout/custom/location_history?hl=en&gl=GB&expflags
#download data from https://www.google.com/settings/takeout/downloads
#web activity is stored here https://history.google.com/history/?utm_source=help


library(jsonlite)
## 
## Attaching package: 'jsonlite'
## 
## The following object is masked from 'package:utils':
## 
##     View
a=fromJSON("C:\\Users\\dell\\Desktop\\Takeout\\Location History\\LocationHistory.json")
b=as.data.frame(a)

mygoog=NULL
mygoog$latitude=b$locations.latitudeE7/10000000
mygoog$longitude=b$locations.longitudeE7/10000000
mygoog$time=as.POSIXct(as.numeric(b$locations.timestampMs)/1000 , origin="1970-01-01")


mygoog=as.data.frame(mygoog)

summary(mygoog$time)
##                  Min.               1st Qu.                Median 
## "2013-07-06 08:10:06" "2013-12-02 22:45:30" "2015-01-04 19:50:26" 
##                  Mean               3rd Qu.                  Max. 
## "2014-10-23 19:49:17" "2015-07-07 21:58:17" "2015-10-24 19:20:49"
library(lubridate)

mygoog$year=year(mygoog$time)
mygoog$month=month(mygoog$time)
mygoog$date=day(mygoog$time)

mygoog2=mygoog[mygoog$time>"2015-10-24 12:30:31",]

library(ggmap)
## Loading required package: ggplot2
Map <- get_googlemap(center = c(lon = median(mygoog2$longitude), lat = median(mygoog2$latitude)),
                     zoom = 10, 
                     size = c(640, 640), 
                     scale = 2, maptype = c("terrain"), 
                     color = "color")
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=28.676333,77.310896&zoom=10&size=640x640&scale=2&maptype=terrain&sensor=false
plot1 <- ggmap(Map) + 
  geom_path(data = mygoog2, aes(x = longitude, y = latitude
  ), 
  alpha = I(0.5), 
  size = 0.8)
suppressWarnings(print(plot1))