I have a list of addresses that I want to geocode. While the Gmaps geocoding API does geocode most of them successfully, there are a few addresses for which it returns nothing. What is the best practice way to handle these?
I tried removing words one by one from the beginning of the address until it is able to return a result, but I fear this sometimes leads to wrong geocoding (i.e., it may, in some cases, interpret the modified address as belonging to another region or country).
for i in range(len(data)): if not((a<data['Lat'][i]<b) or (c<data['Lon'][i]<d)): # desired valid coordinate range place = data['ADDRESS'][i] while True: # repeat the loop until a break is reached try: lat, lon, res = gmaps_geoencoder(place) # this function returns the latitude, longitude, and the jason string from the geocoding API except: place = place.split(' ', 1) # if it can't find anything, remove the first word if (a<lat<b or c<lon<d): # double-checking the desired coordinate range to make sure its correct break data['Lat'][i] = lat data['Lon'][i] = lon data['Result'][i] = res
After doing this, from a preliminary glance at the results, I would say around 15-20% of the locations that weren't geocoded the first time are wrongly geocoded now.
I thought the geocoding API handles this by default as it contains parameters like
formatted_address, which appears in many of my successfully geocoded results. But why is it not able to handle some addresses then? When I tried copy-pasting a few of those addresses randomly in maps.google.com, it does return the location for a filtered version of the address. This leads me to wonder, is the geocoding API not the same as the one used by the Google maps website?
EDIT: Here are 2 addresses for which the API (as well maps.google.com) does not return anything:
CBNC CRH 11B BISMUTH ST RTW TOWNSITE RIOTUBA BATARAZA PALAWAN PHILIPPINES CBNC LRH 54D RTN COMPOUND RIOTUBA BATARAZA PALAWAN PHILIPPINES