Lat-long 使用来自 ggmap 的地理编码

Lat-long using geocode from ggmap

我在使用 包和 geocode 函数为城市获取 latitude-longitude 时遇到错误。

library(ggmap)
# get frequencies
mycities<- as.character(Chennai$City1)
freq <- as.data.frame(table(mycities))
library(plotrix)
library(ggmap)
freq$Freq <- rescale(freq$Freq, c(1,10)) # c(scale_min, scale_max)
geocode(freq$mycities[1])
dput(head(freq))

数据结构为

structure(list(mycities = structure(1:6, .Label = c("Alamanda Rs", 
"Aluva", "Ambasamudram", "Ambattur", "Ameerpet", "Amreli", "Anakapalle", 
"ANATHAPUR", "Anekal", "Aranthangi", "Aravakurichi", "Ariyalur", 
"Asifnagar", "Bagalkot", "Banaganapalle", "Bandlaguda", "Bangalore", 
"BANGALORE", "Bangalore North", "Bangalore South", "Bapatla", 
"Belgaum", "Bellary", "BELLARY", "Bhadrachalam", "Bhadravati", 
"Bibinagar", "Bidar", "Bikkavolu", "Bilgi", "Bobbili", "Buchinaidu Kandriga", 
"Chengalpattu", "Chennai", "Chennai City Corporation", "Chikodi", 
"Chillakur", "Chincholi", "Chinglepet", "Chittapur", "Chittur", 
"Chityal", "CHOUTUPPAL", "COCHIN", "Coimbatore South", "Coonoor", 
"Cuddalore", "Dachepalle", "Davangere", "Dharapuram", "Dindigul", 
"Doddaballapura", "Duggirala", "Egmore", "Ernakulam", "Erode", 
"Etcherla", "Ettayapuram", "Ghanpur (Mulug)", "Gokak", "Gokavaram", 
"Gooty", "Gopalapuram Mandalam", "Gopannapalem", "Gulbarga", 
"Gummidipundi", "Guntur", "Haliyal", "Hassan", "Hindupur", "Hoskote", 
"Hospet", "Hosur", "Humnabad", "Huvinahadagali", "Huzurnagar", 
"Hyd", "Hyderabad", "HYDERABAD", "Iluppur", "INDRAKARAN VILLAGE", 
"Jamkhandi", "Jogipet", "KAKINADA", "Kakinada (Urban)", "Kamalapuram", 
"Kamareddy", "Kanakapura", "Kanayannur", "Kanchipuram", "Kariapatti", 
"Karkala", "Karthikappally", "Karunagapally", "Karur", "Karwar", 
"Khairatabad", "Khammam", "KOCHI", "Kondapalli", "Koppal", "Kothakota", 
"KOTHUR", "Kovvur", "Kozhikode", "Krishna", "Krishnagiri", "Kunigal", 
"Kunnathunad", "Kurnool", "Lalgudi", "Laveru Mandal", "Luxettipet", 
"Maddur", "Madurantakam", "MAHESWARAM MANDAL", "Malur", "Mamidikuduru", 
"Manachanallur", "Manapparai", "Mandapeta", "Mangalore", "MANGALORE", 
"Mangapet", "Mannargudi", "Manugurq", "Manuguru", "Mayiladuthurai", 
"Medikonduru", "Melur", "Mettupalayam", "Mettur", "Miryalguda", 
"Muddebihal", "Mudhol", "Mukundapuram", "Musheerabad", "Muthukur", 
"Mysore", "MYSORE", "NA", "Nagapattinam", "Naidupeta", "Nalgonda", 
"NALGONDA", "Nampally", "Nanguneri", "Nanjangud", "Narsapur", 
"Narsipatnam", "Nedumangad", "Nedungadu Commune Panchayat", "Nelamangala", 
"Nellore", "Nilakkottai", "Ongole", "Palakkad", "Paloncha", "Palwancha", 
"Paravada", "Paravur", "Patancheru", "PATHANAMTHITTA", "Pedagantyada", 
"Peddapalli", "Peddapuram", "Pennagaram", "Perambur Purasawalkam", 
"Periyakulam", "Pollachi", "Pondicherry", "Ponneri", "Prathipadu", 
"Pusapatirega", "Qutubullapur", "R.c.puram", "Radhapuram", "Raichur", 
"Rajahmundry (Urban)", "Ramagundam", "Ramanagara", "Ramanathapuram", 
"Ramdurg", "Ranasthalam Mandal", "Ranebennur", "RANGA REDDY", 
"Rangareddy", "Renigunta", "Saidabad", "Saidapet", "Salem", "Samalkota", 
"Sandur", "Sangareddy", "Sankari", "Sathankulam", "Sathyamangalam", 
"Secunderabad", "Sedam", "Shahapur", "Shaikpet", "Singanamala", 
"Sira", "Sirpur (t)", "Sivakasi", "Somwarpet", "SRIKAKULAM", 
"Sriperumbudur", "SRIPERUMBUDUR", "Stn. Jadcherla", "Sullurpeta", 
"Suryapet", "SURYAPET", "Tada", "TADA", "Tadipatri", "Tallarevu", 
"Tambaram", "Tanuku", "Tanuku (mdl)", "Thanjavur", "Tharangambadi", 
"Thimmajipet", "Thirumalairayan Pattinam Commune Panchayat", 
"Thiruvananthapuram", "Thiruvidaimarudur", "Thondamanadu", "Thoothukkudi", 
"Tindivanam", "Tiruchendur", "Tiruchengodu", "TIRUCHIRAPALLI", 
"Tirukkoyilur", "Tiruklalikundram", "Tirumalagiri", "Tirunelveli", 
"Tiruvallur", "Tiruvannamalai", "Tiruvidamarudur", "Tumkur", 
"Tuni", "TUTICORIN", "Udupi", "Uppal", "Uppalaguptam", "Vaikom", 
"Vedaranyam", "Vedasandur", "Veepangandla", "Vemula", "Venkatachalam", 
"Vepada", "Villianur Commune Panchayat", "Vinjamoor", "Virudhachalam", 
"Virudhunagar", "Virur", "VISAKHAPATNAM", "Vontimitta", "Walajapet", 
"Yerraguntla", "Zaheerabad"), class = "factor"), Freq = c(1, 
1, 1, 4.33333333333333, 1.16666666666667, 1)), row.names = c(NA, 
6L), class = "data.frame")

我收到类似

的错误

Error in geocode(freq$mycities[1]) : is.character(location) is not TRUE

我认为这是因为 google API 发生了变化,这就是它主要使用的内容,这将导致此错误:

geocode failed with status OVER_QUERY_LIMIT

如果您将 source 更改为 dsk 并转换为字符,它应该可以工作:

geocode(as.character(freq$mycities[1]), source = "dsk")

Information from URL : http://www.datasciencetoolkit.org/maps/api/geocode/json?address=Alamanda%20Rs&sensor=false

lon lat
1 -54 -30