# -*- coding: utf-8 -*-
"""
Created on Thu Oct 13 09:10:41 2016

This example downloads live data from the Bike Share program,
which includes where bike stations are located and how many bikes
are currently available, and plots them on a map.

@author: Randy J. Fortier
"""

import gmplot
import urllib.request
import xml.etree.ElementTree as etree

url = 'http://feeds.bikesharetoronto.com/stations/stations.xml'
response  = urllib.request.urlopen(url)
downloaded_data = response.read()
root = etree.fromstring(downloaded_data)

latitudes = []
longitudes = []
for station in root.iter('station'):
    latitude = float(station.find('lat').text)
    longitude = float(station.find('long').text)
    numBikes = int(station.find('nbBikes').text)
    latitudes.append(latitude)
    longitudes.append(longitude)

# 43.6532° N, 79.3832° W

gmap = gmplot.GoogleMapPlotter(43.6532, -79.3832, 14)

#gmap.plot(latitudes, longitudes, 'cornflowerblue', edge_width=10)
#gmap.scatter(latitudes, longitudes, '#3B0B89', size=10, marker=False)
gmap.scatter(latitudes, longitudes, 'cornflowerblue', marker=True)
#gmap.heatmap(latitudes, longitudes)
gmap.scatter([43.65142], [-79.432840], 'k', marker=True)
#
gmap.draw("bike_map.html")
