-1

I am trying to map a list of (~320+) Texas addresses to lat,lng.

I started using geopy (simple example) and it worked for some addresses but it failed on a set of addresses.

So I integrated a backup with googlemaps geocode... but it too failed. Below is the code... see address_to_geoPt.

Yet, when I submit the failed addresses via the browser, it finds the address... any tips on how to get more reliable hits? Which googleapi should I use (see address_to_geoPt_googlemaps())

class GeoMap(dbXLS):
    def __init__(self, **kwargs):
        super(umcGeoMap, self).__init__(**kwargs) 
        # Geo Locator
        self.gl = Nominatim()
        self.gmaps = googlemaps.Client(key='mykeyISworking')


        shName = self.xl.sheet_names[0] if 'sheet' not in kwargs else kwargs['sheet']
        self.df = self.xl.parse(shName)

    def address_to_geoPt(self, addr):
        l = self.geoLocation(addr)
        if l : return (l.latitude, l.longitude) 
        return (np.nan, np.nan)


    def address_to_geoPt_googlemaps(self, addr):
        geocode = self.gmaps.geocode(addr)
        if l == None : return (np.nan, np.nan)

        # Geocoding an address
        locDict = geocode[0]['geometry']['location']
        return(locDict['lat'], locDict['lng'])       


    def address(self, church):
        return (church.Address1 + " "
                                    + church.City + " " 
                                    + church.State + " " 
                                    + church.ZipCode + " "
                                    + church.Country)


    def church_to_geoPt(self, church):
        a = (church.Address1 + " "
             + church.City + " "
             + church.State)
        if pd.isnull(church.geoPt):
            (lat, lng) = self.address_to_geoPt(a)
        else: (lat, lng ) = church.geoPt
        if not pd.isnull(lat) : 
            print("DEBUG to_geoPt 1", lat, lng, a)
            return (lat,lng)
        (lat, lng) = self.address_to_geoPt_googlemaps(a)
        print("DEBUG to_geoPt 2", lat, lng, a)
        return (lat, lng)

The following shows a set of addresses that are not mapped by geocoders.

4     3000 Bee Creek Rd Spicewood TX 78669-5109 USA
6             P O BOX 197 BERTRAM TX 78605-0197 USA
10              2833 Petuma Dr Kempher TX 78639 USA
geocodezip
  • 158,664
  • 13
  • 220
  • 245
frankr6591
  • 1,211
  • 1
  • 8
  • 14
  • The geocoder is subject to a rate limit and a quota, I don't see any attempt to deal with those.. – geocodezip Apr 19 '16 at 06:01
  • Thanks... I was trying to find details on this (found a few links about 10 per sec. etc... ) But when I ran the code again the googlemaps API kicked in and it worked (ie. I created a API key to get the service). – frankr6591 Apr 19 '16 at 20:19

1 Answers1

0

@geocodezip provided the answer... and the code worked the next day.

frankr6591
  • 1,211
  • 1
  • 8
  • 14