Last active
August 29, 2015 14:02
-
-
Save yuu-ito/18e2fac995c67258b6d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# } |
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
使いすぎると結果を返してこなくなる。上限の閾値を確認する。