Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get parking lot API, and retrieve the address. After getting the address, I use pygeocoder to look for a rough coordinates. Finally I can use latitude and longitude to show all the parking lots on Google Maps by pygmaps.
# -*- encoding: utf-8 -*-
import urllib2
import json
import pygmaps
from pygeocoder import Geocoder, GeocoderError
url = '$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
results = Geocoder.geocode(address)
except GeocoderError:
latitude, longitude = results[0].coordinates
lat = float(latitude)
lng = float(longitude)
except ValueError:
print 'Error', address
print lat, lng
mymap.addpoint(lat, lng, '#FF0000')
if __name__ == '__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.