0

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)[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 partial_match and 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
  • Can you give an example of an address that doesn't geocode? It might help us to determine what the problem is. – Mark Ireland Aug 3 '18 at 16:13
  • @MarkIreland I wish I could, but the addresses are confidential – Kristada673 Aug 6 '18 at 2:42
  • It seems like it will be hard to help without examples. Why don't you pick some random addresses (ie not part of your confidential dataset) and run them through your geocoding process until you find ones that cause the same issue. Then share those addresses, and folks here can use them to figure out what's causing the problem. – csk Aug 6 '18 at 18:36
  • Ok, I'm posting 2 examples from my dataset, much easier than finding other valid, real addresses that fit the bill. – Kristada673 Aug 7 '18 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.