#' 取得城市的经纬度
#' @author 李国民
#' @param cities: cities string vector. prov_cities = c("北京", "上海", "天津", "重庆", "哈尔滨", "长春", "沈阳", "呼和浩特", "石家庄", "乌鲁木齐", "兰州", "西宁", "西安", "银川", "郑州", "济南", "太原", "合肥", "武汉", "长沙", "南京", "成都", "贵阳", "昆明", "南宁", "拉萨", "杭州", "南昌", "广州", "福州", "海口", "香港","澳门")
#' @return a data.frame with 3 columns(city,longitude,latitude)
#' @export
#' @examples
#' get_long_lat("南昌")
#' get_long_lat(c("长沙","南昌","郑州","武汉","太原"))
#'
get_long_lat <- function(cities = "南昌"){
library(ggmap)
lt = ggmap::geocode(cities)
# as a data.frame
mydat <- data.frame(cities = cities, lt,stringsAsFactors = FALSE)
mydat
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.