#' get Coordinate from amap
#'
#'
#' get traffic status from amap,there are c(description,expedite,congested,blocked,unkown)
#'
#'
#' @param address character:defalut NULL ,should be rectangle/circle/NULL
#' @param city character:location should be writtend like
#' @param key should be 'json' or 'xml', the type of the result
#' @importFrom xml2 read_html
#' @importFrom rvest html_nodes
#' @importFrom rvest html_text
#' @importFrom rvest %>%
#' @return A vector contains description,expedite,congested,blocked,unkown
#' @export getCoordinateA
#' @examples
#' \dontrun{
#' ## rectangle
#' amap_key='71b002162d43fea08afd5b5e31b030af'
#' getCoordinateA(address='西门ç«<U+393C><U+3E39>',city='fuzhou',key=amap_key)
#' MapBarBus$location=NA
#' for(i in 1:nrow(MapBarBus)){
#' MapBarBus$location[i]=getCoordinateA(address=MapBarBus$station[i],city='ç¦å·ž',key=amap_key)
#' }
#'
#' }
getCoordinateA <- function(address = NULL, city = "ç¦å·ž", key = NULL) {
# url_head='http://restapi.amap.com/v3/geocode/geo?key=您的key&address=ç«è½¦åŒ—ç«™&city=ç¦å·ž'
url_head <- "http://restapi.amap.com/v3/geocode/geo?key="
url <- paste(url_head, key, "&address=", address, "&city=", city, "&output=xml",
sep = "")
web <- read_html(url)
coord <- web %>% html_nodes("location") %>% html_text()
return(coord)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.