3

I'm trying to geocode different IATA airport codes in Italy, with the following (rudimentary) code in ggmap (version 2.4)

#list of all IATA codes
geo_apt <- c("AOI", "BGY", "BLQ", "BRI", "CTA", "FCO", "LIN", "MXP", "NAP", 
"PMF", "PSA", "PSR", "RMI", "TRN", "VCE", "VRN")

#preparing an empty dataframe to store the geocodes
apt_geo <- data.frame(IATA=rep(NA,16), lon=rep(NA,16), lat=rep(NA,16))

#geocoding the codes
for (i in seq_along(geo_apt)) {
  apt_geo[i,1] <- geo_apt[i]
  apt_geo[i,2] <- (geocode(paste(geo_apt[i],"airport")))[1]
  apt_geo[i,3] <- (geocode(paste(geo_apt[i],"airport")))[2]
}

and the geocode function of ggmap works perfectly fine with all of these codes except "PSR"

   IATA        lon      lat
1   AOI  13.363752 43.61654
2   BGY   9.703631 45.66957
3   BLQ  11.287859 44.53452
4   BRI  16.765202 41.13751
5   CTA  15.065775 37.46730
6   FCO  12.246238 41.79989
7   LIN   9.276308 45.45218
8   MXP   8.725531 45.63006
9   NAP  14.286579 40.88299
10  PMF  10.295935 44.82326
11  PSA  10.397884 43.68908
12  PSR -81.117259 33.94855  #<- doens't work
13  RMI  12.618819 44.02289
14  TRN   7.647867 45.19654
15  VCE  12.339771 45.50506
16  VRN  10.890141 45.40000

I've tried to use revgeocode and those coordinates correspond to the following address:

revgeocode(as.numeric(apt_geo[12,2:3]))
#Information from URL : http://maps.googleapis.com/maps/api/geocode/json?latlng=33.948545,-81.1172588&sensor=false
[1] "Kentucky Avenue, West Columbia, SC 29170, USA" 

On the contrary, if I go to Google maps, it works perfectly fine:

map of Pescara airport

Does anybody have a clue on this apparently strange phenomenon?

EDIT

Following one suggestion in the comments below, I tried to use geocode(italy PSR airport) on version 2.4 again and instead of throwing a more accurate result or even the same result, this is the warning I got:

geocode("italy PSR airport")
  lon lat
1  NA  NA
Warning message:
geocode failed with status ZERO_RESULTS, location = "italy PSR airport" 

while with the attempt airport PSR the coordinates are even different from those of PSR airport (at least this time it's an actual airport, although its IATA code is LEX instead of PSR).

revgeocode(as.numeric(geocode("airport PSR")))
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?latlng=38.0381454,-84.5970727&sensor=false
[1] "3895 Terminal Drive, Lexington, KY 40510, USA"
MaZe
  • 239
  • 1
  • 4
  • 13
  • With `ggmap` version 2.5, using `geocode("italy PSR airport")`, you get `12.8333 42.8333`. But `revgeocode` shows it is not correct. –  Jul 30 '15 at 10:01
  • @Pascal how did you install ggmap version 2.5? I have a 2.4 version, and if I try to do `geocode("italy PSR airport")` Warning message: geocode failed with status ZERO_RESULTS, location = "italy PSR airport" ` – MaZe Jul 30 '15 at 10:11
  • Here: https://github.com/dkahle/ggmap#installation –  Jul 30 '15 at 10:12
  • Maybe the API doesn't offer the full data that Google Maps uses? Anyway, `gc <- geocode("Pescara Airport"); revgeocode(unlist(gc[1, ])); # "Abruzzo Airport, Via Tiburtina, Km 229,100, 65131 Pescara PE, Italy"` - I'd suggest decoding the airport IATAs beforehand using e.g. https://en.wikipedia.org/wiki/List_of_airports_in_Italy – lukeA Jul 30 '15 at 10:13
  • @lukeA I suspect as well that the API isn't complete. I knew that with "Pescara airport" it worked, and I know what is what in that list (e.g. AOI stands for Ancona, RMI for Rimini, and so on) but I would rather avoid this solution... my question was more related with the reason of these strange mismatches (as far as I can see, I'm not the only one reporting strange `geocode` results) – MaZe Jul 30 '15 at 10:21

1 Answers1

0

The whole question is a possible duplicate

Nonetheless, I don't get the reason for which the API and Google maps are using different datasets...

Community
  • 1
  • 1
MaZe
  • 239
  • 1
  • 4
  • 13