Skip to content

Instantly share code, notes, and snippets.

@youweit
Created August 1, 2013 17:29
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 youweit/6133479 to your computer and use it in GitHub Desktop.
Save youweit/6133479 to your computer and use it in GitHub Desktop.
#!/usr/bin/pyhton
# -*- encoding: utf-8 -*-
import urllib2
import json
import pygmaps
from pygeocoder import Geocoder, GeocoderError
url = 'http://data.taipei.gov.tw/opendata/apply/query/QzhBMEJFOTctMEEzRC00M0Q2LThDNDktNDVCNDc3NDNDRDBC?$format=json'
def main():
content = urllib2.urlopen(url).read()
datas = json.loads(content)
mymap = pygmaps.maps(25.0336, 121.5644, 16)
for item in datas:
address = u'台北市' + item['area'] + item['address']
print address
try:
results = Geocoder.geocode(address)
except GeocoderError:
continue
latitude, longitude = results[0].coordinates
try:
lat = float(latitude)
lng = float(longitude)
except ValueError:
print 'Error', address
continue
print lat, lng
mymap.addpoint(lat, lng, '#FF0000')
mymap.draw('./parking.html')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment