library(ggplot2)
library(OpenStreetMap)
library(ggmap)
gcodes = geocode(iconv("台灣大學", to = "UTF-8"))
map <- openmap(c(lat = gcodes$lat + 0.005, lon = gcodes$lon - 0.01), c(lat = gcodes$lat -
0.005, lon = gcodes$lon + 0.005), type = "osm")
mapLatLon <- openproj(map)
g <- autoplot(mapLatLon)
g <- g + geom_point(data = gcodes, aes(lon, lat), size = 50, color = "red",
fill = "pink", alpha = 0.3, shape = 20)
g + labs(title = "NTU") + theme(text = element_text(family = "Heiti TC Medium",
size = 16))
Sys.setlocale(category = 'LC_ALL', locale = 'C')
myURL <- URLencode('http://maps.google.com/maps/api/geocode/json?sensor=false&address=台灣大學')
con <- url(myURL)
data.json <- fromJSON(paste(readLines(con,encoding='UTF-8'), collapse = ""),encoding='UTF-8')
close(con)
Sys.setlocale(category = 'LC_ALL', locale = '')
data.json <- unlist(data.json)
lat <- data.json["results.geometry.location.lat"]
lng <- data.json["results.geometry.location.lng"]
gcodes <- as.numeric(c(lat, lng))
names(gcodes) <- c("lat", "lon")