#Mapa Estaciones Mio ###Datos 2015

library(ggplot2)
library(ggmap)

#Registro en Google
register_google(apikey)

#Mapa de la Ciudad de Cali
qmap("Cali", zoom=10)

# get_googlemap() can access Google Static Maps API and customize the map attributes. See:
# https://developers.google.com/maps/documentation/static-maps/
qmap("Cali", zoom = 10, maptype = "hybrid")

# The same map from a different map provider. See: http://maps.stamen.com/
qmap("Cali", zoom = 10, source = "stamen", maptype = "toner")

#Load a map
city <- get_map("Cali", zoom = 12)

# With that data and the long/lat of the center you can get the ggplot2 object used by ggmap to plot the raster image on top.
str(city)
##  'ggmap' chr [1:1280, 1:1280] "#CED4C9" "#D3D8CE" "#D8DFD3" "#DCE2D6" ...
##  - attr(*, "source")= chr "google"
##  - attr(*, "maptype")= chr "terrain"
##  - attr(*, "zoom")= num 12
##  - attr(*, "bb")= tibble [1 x 4] (S3: tbl_df/tbl/data.frame)
##   ..$ ll.lat: num 3.34
##   ..$ ll.lon: num -76.6
##   ..$ ur.lat: num 3.56
##   ..$ ur.lon: num -76.4
# Generar Mapa
caliMap <- ggmap(city)

# Importar Dataset
MioStops <- read.delim(file="MIO_STOPS.txt")

# Generar Mapa
caliMap <- ggmap(city)

# Agregar puntos del mapa
caliMap <- caliMap + geom_point(data = MioStops, aes(x= DECIMALLONGITUDE, y = DECIMALLATITUDE), color = "red", alpha = 0.3)

# Plot the map
caliMap

#ZOOMING

# Cali coords
CaliCoords <- geocode("Chipichape,Cali")

# Retrieve the map fron the provider
cityCenter <- get_map(c(CaliCoords$lon, CaliCoords$lat), source= "stamen", maptype="toner", zoom = 16)

# Generate the map
caliCenter <- ggmap(cityCenter)

# Add points to the map
caliMap <- caliMap + geom_point(data = MioStops, aes(x= DECIMALLONGITUDE, y = DECIMALLATITUDE), color = "red", alpha = 0.3)

# Plot the map
caliCenter