Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.