Created
August 1, 2013 17:29
-
-
Save youweit/6133479 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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