Skip to content

Instantly share code, notes, and snippets.

@wholmgren
Created August 5, 2014 23:50
Show Gist options
  • Save wholmgren/6330bec8fc0813e65fcc to your computer and use it in GitHub Desktop.
Save wholmgren/6330bec8fc0813e65fcc to your computer and use it in GitHub Desktop.
get time zone from lat lon via google using python
import pytz
import requests
import numpy as np
now_timestamp = np.datetime64(datetime.datetime.utcnow()).astype(float)/1e6
lat = 32.2
lon = -111.9
payload = {'location':'{},{}'.format(lat, lon), 'timestamp':str(now_timestamp)}
tz_response = requests.get('https://maps.googleapis.com/maps/api/timezone/json', params=payload)
thetz = pytz.timezone(tz_response.json()['timeZoneName'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment