Skip to content

Instantly share code, notes, and snippets.

@russch
Created June 19, 2016 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russch/9ffe24f60dd696b79d2d65924b46347d to your computer and use it in GitHub Desktop.
Save russch/9ffe24f60dd696b79d2d65924b46347d to your computer and use it in GitHub Desktop.
freegeoip <- function(ip, format = ifelse(length(ip)==1,'list','dataframe'))
{
if (1 == length(ip))
{
# a single IP address
require(rjson)
url <- paste(c("http://freegeoip.net/json/", ip), collapse='')
ret <- fromJSON(readLines(url, warn=FALSE))
ret <- data.frame(t(unlist(ret)))
latlon <- paste(ret$latitude,ret$longitude,sep=",")
return(latlon)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment