如何通过R中的ggmap包获取邮政编码数据集

时间:2017-04-19 21:13:31

标签: r ggmap

使用geocode('Zip')我可以获得位置坐标。 给定坐标怎么样,我可以获得该位置的邮政编码吗? 例如

geocode('130022,长春')

这给了我家乡的坐标。 130022是邮政编码,长春是城市。通过这样做,我想获得长春市独特的地理坐标,即(125.35,43.86364)。 如果我给出坐标,如何获取邮政编码数据怎么办?

1 个答案:

答案 0 :(得分:2)

使用revgeocode()

revgeocode(location = c(125.35, 43.8634))
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?latlng=43.8634,125.35&sensor=false
[1] "Jun Zhuan Hu Tong, Nanguan Qu, Changchun Shi, Jilin Sheng, China, 130022"

如果您想了解更多细节,请指定output = 'all'

res <- revgeocode(location = c(125.35, 43.8634), output = 'all')

str(res)
# List of 2
# $ results:List of 6
# ..$ :List of 5
# .. ..$ address_components:List of 6
# .. .. ..$ :List of 3
# .. .. .. ..$ long_name : chr "Jun Zhuan Hu Tong"
# .. .. .. ..$ short_name: chr "Jun Zhuan Hu Tong"
# .. .. .. ..$ types     : chr "route"
# .. .. ..$ :List of 3
# .. .. .. ..$ long_name : chr "Nanguan Qu"
# .. .. .. ..$ short_name: chr "Nanguan Qu"
# .. .. .. ..$ types     : chr [1:3] "political" "sublocality" "sublocality_level_1"
# .. .. ..$ :List of 3
# .. .. .. ..$ long_name : chr "Changchun Shi"
# .. .. .. ..$ short_name: chr "Changchun Shi"
# .. .. .. ..$ types     : chr [1:2] "locality" "political"
# .. .. ..$ :List of 3
# .. .. .. ..$ long_name : chr "Jilin Sheng"
# .. .. .. ..$ short_name: chr "Jilin Sheng"
# .. .. .. ..$ types     : chr [1:2] "administrative_area_level_1" "political"
# ... etc