Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
badbye committed May 24, 2017
1 parent 7837955 commit cb6bb79
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 12 deletions.
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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')"
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
Version: 0.2.1
Encoding: UTF-8
Author: yalei Du <[email protected]>
Maintainer: yalei Du <[email protected]>
Expand Down
7 changes: 6 additions & 1 deletion R/geoconv.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
9 changes: 8 additions & 1 deletion R/getCoordinate.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
16 changes: 10 additions & 6 deletions R/getLocation.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)<limit){
res<-getLocation.core(location, output, formatted , pois)
res<-getLocation.core(location, output, formatted , pois, map_ak = map_ak)
}else if(require(parallel)){
cl <- makeCluster(getOption("cl.cores", detectCores()*0.8))
res<-parApply(cl,X = location,MARGIN = 1,FUN = function(x){
Expand Down
7 changes: 6 additions & 1 deletion R/getPlace.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ url_character = function(x){
#' sh_mcdonald = getPlace('麦当劳', '上海')
#' }
getPlace = function(place=NULL, city='北京', page_size=20,
pages=Inf, scope=1, verbose=TRUE){
pages=Inf, scope=1, verbose=TRUE, 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)
}
### character
place = url_character(place)
city = url_character(city)
Expand Down
8 changes: 7 additions & 1 deletion R/getRoute.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ getRouteXML = function(origin, destination, mode='driving',
destination_region = NA,
tactics = 11,
coord_type = 'bd09ll',
output = 'xml'){
output = 'xml',
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 (is.na(region)){
if (is.na(origin_region) & is.na(destination_region)) {
stop('Argument "region" is not setted!')
Expand Down
9 changes: 9 additions & 0 deletions R/onLoad.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.onAttach <- function(libname, pkgname) {
# Runs when attached to search() path such as by library() or require()
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')`")
}
}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ baidumap

R interface of baidu map api,just like ggmap but get map from baidu api instead of google or openstreet.

### install
## Installation
```
library(devtools)
install_github('badbye/baidumap')
```

## Usage

Apply an application from [lbsyun.baidu.com](http://lbsyun.baidu.com/apiconsole/key). Then register you key here.
```
library(baidumap)
options(baidumap.key = 'XXX fill your key here XXX')
```


### getLocation
Get location from coordinates data.
```
Expand Down
Empty file added tests/test.R
Empty file.

0 comments on commit cb6bb79

Please sign in to comment.