Libraries
library(ggplot2)
library(ggmap)
# You should get your own api key from Google. Follow: https://cloud.google.com/maps-platform/
register_google(apiKey)
# Quick plot of the City of Cali / Google Maps provider
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 × 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
# Get data from file
MioStops <- read.delim(file="MIO_STOPS.txt")
# Generate the map
caliMap <- ggmap(city)
# Add points to the map
caliMap <- caliMap + geom_point(aes(x= DECIMALLONGITUDE, y = DECIMALLATITUDE),data = MioStops, color = "red", alpha = 0.3)
# Plot the map
caliMap
# 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
caliCenter <- caliCenter + geom_point(aes(x= DECIMALLONGITUDE, y = DECIMALLATITUDE),data = MioStops, color = "red")
# Plot the map
caliCenter
Busque en Google maps la dirección de su casa. Haga un mapa centrado sobre su casa y dibuje los paraderos del Mio mas cercanos.