def reverse_geocode(point): try: g = Google(settings.GOOGLE_MAPS_API_KEY) (new_place,new_point) = g.reverse((point.y, point.x)) return new_place except: pass return ""
def save(self,**kwargs): if not self.location: address = u'%s %s' % (self.city, self.address) address=address.encode("utf-8") geocoder=Google() try: _, latlon = geocoder.geocode(address) except ("Geocodowanie blad", GQueryError, ValueError): pass else: point = "POINT(%s %s)" % (latlon[1], latlon[0]) self.location = geos.fromstr(point) super(Place, self).save()
def setUp(self): from geopy.geocoders.google import Google self.geocoder = Google()
def geocode(name, exactly_one=False): try: g = Google(settings.GOOGLE_MAPS_API_KEY) return list(g.geocode(name, exactly_one=exactly_one)) except: logging.error("Could not get reverse geocode for {{point.y}}-{{point.x}}")