2011-04-21

quick iphone location data

I threw together some code to look at my iphone location data. There are a couple strange features to the data, and I'm eager to get my hands on a friend’s iphone4 data to see if it is the same. Timestamps are often the same — I’ll have 350 entries on some days, but only 7 or max 10 unique timestamps. On the other hand, location points themselves are pretty good.

Yup. NYC, Chicago, and I was in DC around xmas.

There are a couple wild points in NJ, and perhaps the ocean, making the bounding box too large here.

This is a couple weeks ago when I was out in Elmhurst, Queens, for the Thai Songkran festival. See my pictures (with amod gps logger geotags) here!

I flew into Chicago on New Year’s Eve. But, no points are stored from the rest of the day, only the train ride in, from O’hare apparently.

And last time I was in chicago, on one day I only went to the Maxwell Street Market for mexican food, and mostly hung out at home. Which is somewhere not far from that cloud of points.

Here’s the code.

library(RgoogleMaps)
library(RSQLite)
dbh <- dbConnect("SQLite", "~/Consolidated.db")
Loc <- dbReadTable(dbh, "CellLocation")
dbDisconnect(dbh)
Loc$time <- as.POSIXct(Loc$Timestamp,
                       origin=as.Date("2001-01-01"))
Loc$date <- as.Date(Loc$time)
Loc <- subset(Loc, Latitude != 0)

## Focus on a couple a specific days
Days <- list(
             ## whole thing
             all=Loc
             ## last sunday, park, soho
             Sunday <- Loc[Loc$date == as.Date("2011-04-17"),],
             ## songkran
             Songkran <- Loc[Loc$date == as.Date("2011-04-10"),],
             ## NYE
             Nye <- Loc[Loc$date == as.Date("2010-12-31"),],
             ## Maxwell
             Maxwell <- Loc[Loc$date == as.Date("2011-04-04"),],
             )



lapply(Days, function(Df) {
  png(file=paste(paste(range(Df$Latitude),collapse=""),
        ".png",collapse="",sep=""),
      640,640)
  bb <- qbbox(lat=range(Df$Latitude),
              lon=range(Df$Longitude))
  ##m <- c(mean(range(Df$Latitude)), # better for 'all' plot
  ##       mean(range(Df$Longitude)))
  m <- c(median(Df$Latitude),
         median(Df$Longitude))
  
  zoom <- min(MaxZoom(latrange=bb$latR,lonrange=bb$lonR))
  Map <- GetMap.bbox(bb$lonR,
                     bb$latR,
                     center=m,zoom=zoom,
                     maptype="terrain",
                     NEWMAP=TRUE,
                     destfile="tempmap.jpg",
                     RETURNIMAGE=TRUE,
                     GRAYSCALE=TRUE)
  tmp <- PlotOnStaticMap(lat=Df$Latitude, lon=Df$Longitude,
                         cex=.7,pch=20,col="#00aa0065",
                         MyMap=Map, NEWMAP=FALSE)
  dev.off()
})

2 comments:

Dirk Eddelbuettel said...

Very nice, and extra points for code! By my (highly imperfect :-) count, you were already beaten by
the speedy Prof Jackman.

Tian Zheng said...

Interesting. Can't wait to try on my iPhone data. I wonder, without reading further on this topic elsewhere, whether the phone only sends location data when we use apps that records or uses location info. This might explain why train rides got most of your enties in Chicago, as you were using a lot of apps to kill time on the train.