Skip to content

Instantly share code, notes, and snippets.

@projectyotta
Created November 7, 2017 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save projectyotta/ad17bf4d40e7dc369b95396d0afafafa to your computer and use it in GitHub Desktop.
Save projectyotta/ad17bf4d40e7dc369b95396d0afafafa to your computer and use it in GitHub Desktop.
reverse geocoding using google maps API in python
# coding: utf-8
# In[107]:
url=[]
latlng=["56.2,-153.1","57.2,-158.1","57.2,-157.1","57.2,-156.1","57.2,-155.1","57.2,-154.1","57.2,-153.1","58.2,-158.1","58.2,-157.1","58.2,-156.1","58.2,-155.1","58.2,-154.1","58.2,-153.1","59.2,-161.1","59.2,-160.1","59.2,-159.1","59.2,-158.1","59.2,-157.1","59.2,-156.1","59.2,-155.1","59.2,-154.1","59.2,-153.1","60.2,-165.1","60.2,-164.1","60.2,-163.1","60.2,-162.1","60.2,-161.1","60.2,-160.1","60.2,-159.1","60.2,-158.1","60.2,-157.1","60.2,-156.1","60.2,-155.1","60.2,-154.1","60.2,-153.1","60.2,-152.1","60.2,-151.1","60.2,-150.1","60.2,-149.1","60.2,-148.1","60.2,-147.1","60.2,-146.1","60.2,-145.1","60.2,-144.1","60.2,-143.1","60.2,-142.1","60.2,-141.1","61.2,-165.1","61.2,-164.1","61.2,-163.1","61.2,-162.1","61.2,-161.1","61.2,-160.1","61.2,-159.1","61.2,-158.1","61.2,-157.1","61.2,-156.1","61.2,-155.1","61.2,-154.1","61.2,-153.1","61.2,-152.1","61.2,-151.1","61.2,-150.1","61.2,-149.1","61.2,-148.1","61.2,-147.1","61.2,-146.1","61.2,-145.1","61.2,-144.1","61.2,-143.1","61.2,-142.1","61.2,-141.1","62.2,-165.1","62.2,-164.1","62.2,-163.1","62.2,-162.1","62.2,-161.1","62.2,-160.1","62.2,-159.1","62.2,-158.1","62.2,-157.1","62.2,-156.1","62.2,-155.1","62.2,-154.1","62.2,-153.1","62.2,-152.1","62.2,-151.1","62.2,-150.1","62.2,-149.1","62.2,-148.1","62.2,-147.1","62.2,-146.1","62.2,-145.1","62.2,-144.1","62.2,-143.1","62.2,-142.1","62.2,-141.1","63.2,-160.1","63.2,-159.1","63.2,-158.1","63.2,-157.1","63.2,-156.1","63.2,-155.1","63.2,-154.1","63.2,-153.1","63.2,-152.1","63.2,-151.1","63.2,-150.1","63.2,-149.1","63.2,-148.1","63.2,-147.1","63.2,-146.1","63.2,-145.1","63.2,-144.1","63.2,-143.1","63.2,-142.1","63.2,-141.1","64.2,-160.1","64.2,-159.1","64.2,-158.1","64.2,-157.1","64.2,-156.1","64.2,-155.1","64.2,-154.1","64.2,-153.1","64.2,-152.1","64.2,-151.1","64.2,-150.1","64.2,-149.1","64.2,-148.1","64.2,-147.1","64.2,-146.1","64.2,-145.1","64.2,-144.1","64.2,-143.1","64.2,-142.1","64.2,-141.1","65.2,-167.1","65.2,-166.1","65.2,-165.1","65.2,-164.1","65.2,-163.1","65.2,-162.1","65.2,-161.1","65.2,-160.1","65.2,-159.1","65.2,-158.1","65.2,-157.1","65.2,-156.1","65.2,-155.1","65.2,-154.1","65.2,-153.1","65.2,-152.1","65.2,-151.1","65.2,-150.1","65.2,-149.1","65.2,-148.1","65.2,-147.1","65.2,-146.1","65.2,-145.1","65.2,-144.1","65.2,-143.1","65.2,-142.1","65.2,-141.1","66.2,-167.1","66.2,-166.1","66.2,-165.1","66.2,-164.1","66.2,-163.1","66.2,-162.1","66.2,-161.1","66.2,-160.1","66.2,-159.1","66.2,-158.1","66.2,-157.1","66.2,-156.1","66.2,-155.1","66.2,-154.1","66.2,-153.1","66.2,-152.1","66.2,-151.1","66.2,-150.1","66.2,-149.1","66.2,-148.1","66.2,-147.1","66.2,-146.1","66.2,-145.1","66.2,-144.1","66.2,-143.1","66.2,-142.1","66.2,-141.1","67.2,-163.1","67.2,-162.1","67.2,-161.1","67.2,-160.1","67.2,-159.1","67.2,-158.1","67.2,-157.1","67.2,-156.1","67.2,-155.1","67.2,-154.1","67.2,-153.1","67.2,-152.1","67.2,-151.1","67.2,-150.1","67.2,-149.1","67.2,-148.1","67.2,-147.1","67.2,-146.1","67.2,-145.1","67.2,-144.1","67.2,-143.1","67.2,-142.1","67.2,-141.1","68.2,-167.1","68.2,-166.1","68.2,-165.1","68.2,-164.1","68.2,-163.1","68.2,-162.1","68.2,-161.1","68.2,-160.1","68.2,-159.1","68.2,-158.1","68.2,-157.1","68.2,-156.1","68.2,-155.1","68.2,-154.1","68.2,-153.1","68.2,-152.1","68.2,-151.1","68.2,-150.1","68.2,-149.1","68.2,-148.1","68.2,-147.1","68.2,-146.1","68.2,-145.1","68.2,-144.1","68.2,-143.1","68.2,-142.1","68.2,-141.1","69.2,-167.1","69.2,-166.1","69.2,-165.1","69.2,-164.1","69.2,-163.1","69.2,-162.1","69.2,-161.1","69.2,-160.1","69.2,-159.1","69.2,-158.1","69.2,-157.1","69.2,-156.1","69.2,-155.1","69.2,-154.1","69.2,-153.1","69.2,-152.1","69.2,-151.1","69.2,-150.1","69.2,-149.1","69.2,-148.1","69.2,-147.1","69.2,-146.1","69.2,-145.1","69.2,-144.1","69.2,-143.1","69.2,-142.1","69.2,-141.1","70.2,-162.1","70.2,-161.1","70.2,-160.1","70.2,-159.1","70.2,-158.1","70.2,-157.1","70.2,-156.1","70.2,-155.1","70.2,-154.1","70.2,-153.1","70.2,-152.1","70.2,-151.1","70.2,-150.1","70.2,-149.1","70.2,-148.1","70.2,-147.1","70.2,-146.1","70.2,-145.1","70.2,-144.1","70.2,-143.1","70.2,-142.1","70.2,-141.1"]
base_url="https://maps.googleapis.com/maps/api/geocode/json?latlng="
key="&key=lulz"
for i in range(0,len(latlng)):
x = base_url + latlng[i] + key
url.append(x)
# In[108]:
import time
add1 = []
import requests
for i in range(0,len(latlng)):
req = requests.get(url[i])
val = req.json()
address=val['results'][0]['formatted_address']
print(latlng[i] + "_" + address)
time.sleep(1)
# In[79]:
latlng[470]
# In[66]:
import pandas as pd
df = pd.DataFrame(latlng, add, columns=columns)
# In[60]:
add
# In[21]:
# In[54]:
# In[ ]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment