Skip to content

Instantly share code, notes, and snippets.

@yuu-ito
Last active August 29, 2015 14:02
Show Gist options
  • Save yuu-ito/18e2fac995c67258b6d5 to your computer and use it in GitHub Desktop.
Save yuu-ito/18e2fac995c67258b6d5 to your computer and use it in GitHub Desktop.
get_latlng_from_address<-function(zipcode){
require("rjson")
url.template<-"http://maps.googleapis.com/maps/api/geocode/json?language=ja&address"
url <- paste(url.template,zipcode,sep="=")
map_data <- fromJSON(paste(readLines(url), collapse=""))
if(map_data$status=="OK"){
address_info <- map_data$results[[1]]$address_components
location <- map_data$results[[1]]$geometry$location
res <- data.frame(
zipcode= zipcode,
res_zip_code = address_info[[1]]$short_name,
name1 = address_info[[4]]$short_name,
name2 = address_info[[3]]$short_name,
name3 = address_info[[2]]$short_name,
lat = location$lat,
lng = location$lng,
status = map_data$status
)
}else{
res <- data.frame(
zip_code = zipcode,
res_zip_code = "no_result",
name1 = "no_result",
name2 = "no_result",
name3 = "no_result",
lat = NA,
lng = NA,
status = map_data$status
)
}
return(res)
}
# get_latlng_from_address(1000001)
## http://www.post.japanpost.jp/zipcode/dl/oogaki-zip.html
# tokyo.csv <- read.csv("~/Downloads/13tokyo/13TOKYO.CSV",head=F)
# res <-get_latlng_from_address(tokyo.csv$zipcode[1])
# for(i in tokyo.csv.fix$zipcode[-1]){
# a <- get_latlng_from_address(i)
# rbind(res,a) ->> res
# }
@yuu-ito
Copy link
Author

yuu-ito commented Jun 17, 2014

> get_latlng_from_address(1000001)
Loading required package: rjson
  zip_code res_zip_code     name1     name2     name3 lat lng           status
1  1000001    no_result no_result no_result no_result  NA  NA OVER_QUERY_LIMIT

使いすぎると結果を返してこなくなる。上限の閾値を確認する。

@yuu-ito
Copy link
Author

yuu-ito commented Jun 17, 2014

https://developers.google.com/maps/documentation/business/faq#js_usage_limits

ジオコーディング 1 日あたり 100,000 リクエスト。

これに引っかからないように注意してクエリを投げる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment