Skip to content

Instantly share code, notes, and snippets.

@jordotech
Created October 6, 2017 22:59
Show Gist options
  • Save jordotech/16c980cdecaa7ab15ec83454720bb68c to your computer and use it in GitHub Desktop.
Save jordotech/16c980cdecaa7ab15ec83454720bb68c to your computer and use it in GitHub Desktop.
geocoder.google()
import geocoder
def get_shop_coordinates(shop):
if len(shop.postalcode) and len(shop.street) > 1:
address_to_check = '%s %s' % (shop.street, shop.postalcode)
g = geocoder.google(address_to_check)
ret = {}
if g.lat <> 0 and g.lng <> 0:
ret['latitude'] = g.lat
ret['longitude'] = g.lng
return ret
else:
message = 'Failed to get lat/lon of shop: %s id: %s' % (shop.name, shop.id)
shop_url = '%s/storelocator/shops/%s' % (settings.SITE_DOMAIN, shop.id)
if settings.DEBUG:
client.http_context({'url': shop_url})
client.captureMessage(message)
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment