diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3e2851b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +language: r +r: + - oldrel + - release + - devel +cache: + packages: yes + directories: + - $HOME/cache +r_packages: + - devtools + - testthat + - ggmap + - RgoogleMaps + - png + - RCurl + - rjson + - XML + +before_script: + - Rscript -e "if (!require('webshot')) devtools::install_github('wch/webshot')" + +# run tests +script: + - Rscript -e "testthat::test_dir('tests')" \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 26e4ec6..cdcf348 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: baidumap Title: A package for spatial visualization with Baidu -Version: 0.2 +Version: 0.2.1 Encoding: UTF-8 Author: yalei Du Maintainer: yalei Du diff --git a/R/geoconv.R b/R/geoconv.R index 9cd2ed6..010cbdc 100644 --- a/R/geoconv.R +++ b/R/geoconv.R @@ -7,7 +7,12 @@ #' @importFrom rjson fromJSON #' @importFrom RCurl getURL #' @export geoconv -geoconv = function(geocode, from=3, to=5){ +geoconv = function(geocode, from=3, to=5, map_ak=''){ + if (map_ak == '' && is.null(getOption('baidumap.key'))){ + stop('Please register AK by ') + }else{ + map_ak = ifelse(map_ak == '', getOption('baidumap.key'), map_ak) + } if (class(geocode) %in% c('data.frame', 'matrix')){ geocode = as.matrix(geocode) code = apply(geocode, 1, function(x) paste0(x[1], ',', x[2])) diff --git a/R/getCoordinate.R b/R/getCoordinate.R index 489fc33..8779e4b 100644 --- a/R/getCoordinate.R +++ b/R/getCoordinate.R @@ -1,4 +1,11 @@ -getCoordinate.core = function(address, city=NULL, output='json', formatted = F){ +getCoordinate.core = function(address, city=NULL, + output='json', formatted = F, + map_ak = ''){ + if (map_ak == '' && is.null(getOption('baidumap.key'))){ + stop('Please register AK by ') + }else{ + map_ak = ifelse(map_ak == '', getOption('baidumap.key'), map_ak) + } ### address if (grepl(' |#', address)) warning('address should have blank character!') address = gsub(' |#', '', address) diff --git a/R/getLocation.R b/R/getLocation.R index 65f5582..d4909b8 100644 --- a/R/getLocation.R +++ b/R/getLocation.R @@ -1,6 +1,5 @@ -map_ak = 'wwZFCIqxIqjRGMVsZ0qgTh7D' - -getLocation.core = function(location, output='json', formatted = F, pois=0){ +getLocation.core = function(location, output='json', formatted = F, + pois=0, map_ak){ ##### URL if (!class(location) %in% c('matrix', 'data.frame')){ location = matrix(location, ncol=2, byrow=T) @@ -62,10 +61,15 @@ getLocation.core = function(location, output='json', formatted = F, pois=0){ #' location = getLocation(loc, formatted = T) #' } #' -getLocation= - function (location, output = "json", formatted = F, pois = 0,limit=600) { +getLocation = function (location, output = "json", formatted = F, + pois = 0, limit=600, map_ak = '') { + if (map_ak == '' && is.null(getOption('baidumap.key'))){ + stop('Please register AK by ') + }else{ + map_ak = ifelse(map_ak == '', getOption('baidumap.key'), map_ak) + } if(NROW(location)