Created
          February 2, 2015 22:18 
        
      - 
      
 - 
        
Save cjwinchester/a48dce96ab9152d39adc to your computer and use it in GitHub Desktop.  
    Google geocoder script
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """ | |
| assumes you're feeding it a text file of addresses | |
| spits out a pipe-delimited file of coordinates | |
| """ | |
| import csv | |
| import json | |
| import requests | |
| f = open('output.txt', 'wb') | |
| with open('input.txt', 'rb') as csvfile: | |
| xreader = csv.reader(csvfile, delimiter="\t") | |
| for row in xreader: | |
| row = row[0].replace(" ","+") | |
| r = requests.get('https://maps.googleapis.com/maps/api/geocode/json?address=' + row[0] + '&key=YOUR_API_KEY_HERE') | |
| j = r.json() | |
| lat = j['results'][0]['geometry']['location']['lat'] | |
| lng = j['results'][0]['geometry']['location']['lng'] | |
| w = "|".join((str(lat),str(lng))) | |
| f.write(w + "\n") | |
| print row | |
| f.flush() | |
| f.close() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment