Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R geocode query error when address has hash

An address containing a "#" (for example an apartment number) frequently gives an incorrect location result, both with ggmap::geocode and with google maps as well, so this is not strictly an R question. In this example, adding a "#3" after the street address changes the location result from Illinois to California:

> test <- geocode('1200 Davis St, Evanston, IL 60202', source='google', output='more')
> test[, c('lon', 'lat', 'administrative_area_level_1')]
        lon      lat administrative_area_level_1
1 -87.68978 42.04627                    Illinois

> testhash <- geocode('1200 Davis St #3, Evanston, IL 60202', source='google', output='more')
> testhash[, c('lon', 'lat', 'administrative_area_level_1')]     
        lon      lat administrative_area_level_1
1 -122.1692 37.72169                  California

If you experiment with google maps directly, sometimes adding a hash into an address seems to confuse the lookup, generating a variety of geographically dispersed results. This doesn't always happen, but in my experience happens frequently. It's easily fixed (there's no need for an apartment number when geocoding) but I'm wondering why it happens and if there are other cautions about entering addresses.

like image 258
Robert McDonald Avatar asked Oct 29 '22 12:10

Robert McDonald


1 Answers

Google has recommendations in regard to address formatting in Geocoding API. Particularly they suggest do not specify additional elements like apartment number or floor numbers in requests.

You can check the complete list of recommendations in Google Maps FAQ:

https://developers.google.com/maps/faq#geocoder_queryformat

The relevant part is

Do not specify additional address elements such as business names, unit numbers, floor numbers, or suite numbers that are not included in the address as defined by the postal service of the country concerned. Doing so may result in responses with ZERO_RESULTS.

I hope this helps!

like image 98
xomena Avatar answered Nov 15 '22 05:11

xomena