2017-04-19 139 views
1

通过使用geocode('Zip')我可以获取位置坐标。 给定坐标怎么样,我可以得到该位置的邮政编码吗? 例如如何通过ggmap包获取邮政编码数据集R

geocode('130022,长春') 

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

回答

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 
相关问题