Skip to content

Commit

Permalink
msg
Browse files Browse the repository at this point in the history
  • Loading branch information
badbye committed May 24, 2017
1 parent 9878742 commit 46a5d19
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: baidumap
Title: A package for spatial visualization with Baidu
Version: 0.2.1
Version: 0.2.2
Encoding: UTF-8
Author: yalei Du <[email protected]>
Maintainer: yalei Du <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion R/geoconv.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @export geoconv
geoconv = function(geocode, from=3, to=5, map_ak=''){
if (map_ak == '' && is.null(getOption('baidumap.key'))){
stop('Please register AK by ')
stop(Notification)
}else{
map_ak = ifelse(map_ak == '', getOption('baidumap.key'), map_ak)
}
Expand Down
9 changes: 8 additions & 1 deletion R/getBaiduMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
#' ## do not print messages
#' p <- getBaiduMap(messaging = F)
#' }
getBaiduMap = function(location, width=400, height = 400, zoom=10, scale=2, color = "color", messaging = TRUE){
getBaiduMap = function(location, width=400, height = 400, zoom=10,
scale=2, color = "color", messaging = TRUE,
map_ak = ''){
if (map_ak == '' && is.null(getOption('baidumap.key'))){
stop(Notification)
}else{
map_ak = ifelse(map_ak == '', getOption('baidumap.key'), map_ak)
}
## location
if (is.character(location) && length(location) == 1){
location_cor = getCoordinate(location, formatted=T)
Expand Down
18 changes: 9 additions & 9 deletions R/getCoordinate.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
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 (any(grepl(' |#', address))) warning('address should not have blank character!')
address = gsub(' |#', '', address)
Expand Down Expand Up @@ -65,19 +60,24 @@ getCoordinate.core = function(address, city=NULL,
#' ## vectorization, return a matrix
#' getCoordinate(c('北京大学', '清华大学'), formatted = T)
#' }
getCoordinate=function(address, city=NULL, output='json', formatted = F,limit=600){
getCoordinate=function(address, city=NULL, output='json', formatted = F,limit=600, map_ak=''){
if (map_ak == '' && is.null(getOption('baidumap.key'))){
stop(Notification)
}else{
map_ak = ifelse(map_ak == '', getOption('baidumap.key'), map_ak)
}
if(length(address)<limit){
res<-getCoordinate.core(address, city, output , formatted)
res<-getCoordinate.core(address, city, output , formatted, map_ak)
}else if(require(parallel)){
cl <- makeCluster(getOption("cl.cores", detectCores()*0.8))
res<-parLapply(cl,X = address,fun = function(x){
getCoordinate.core(x, city, output , formatted)
getCoordinate.core(x, city, output , formatted, map_ak)
})
res<-do.call('rbind',res)
stopCluster(cl)
}else{
warning('can not run in parallel mode without package parallel')
res<-getCoordinate.core(address, city, output , formatted)
res<-getCoordinate.core(address, city, output , formatted, map_ak)
}
res
}
4 changes: 2 additions & 2 deletions R/getLocation.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ getLocation.core = function(location, output='json', formatted = F,
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 ')
stop(Notification)
}else{
map_ak = ifelse(map_ak == '', getOption('baidumap.key'), map_ak)
}
Expand All @@ -81,4 +81,4 @@ getLocation = function (location, output = "json", formatted = F,
res<-getLocation.core(location, output, formatted , pois)
}
res
}
}
2 changes: 1 addition & 1 deletion R/getPlace.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ url_character = function(x){
getPlace = function(place=NULL, city='北京', page_size=20,
pages=Inf, scope=1, verbose=TRUE, map_ak=''){
if (map_ak == '' && is.null(getOption('baidumap.key'))){
stop('Please register AK by ')
stop(Notification)
}else{
map_ak = ifelse(map_ak == '', getOption('baidumap.key'), map_ak)
}
Expand Down
2 changes: 1 addition & 1 deletion R/getRoute.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ getRouteXML = function(origin, destination, mode='driving',
output = 'xml',
map_ak=''){
if (map_ak == '' && is.null(getOption('baidumap.key'))){
stop('Please register AK by ')
stop(Notification)
}else{
map_ak = ifelse(map_ak == '', getOption('baidumap.key'), map_ak)
}
Expand Down
10 changes: 7 additions & 3 deletions R/onLoad.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
if (interactive()) {
v = packageVersion("baidumap")
message('baidumap ', v)
message('Apply an application from here: http://lbsyun.baidu.com/apiconsole/key')
message("Then register you key by running `options(baidumap.key = 'xxx')`")
message(Notification)
}
}
}

Notification <- paste('Apply an application from here: http://lbsyun.baidu.com/apiconsole/key',
"Then register you key by running `options(baidumap.key = 'xxx')`",
sep = '\n')

0 comments on commit 46a5d19

Please sign in to comment.