Learn R Programming

baidumap (version 0.2.2)

getLocation: Get location from coordinate Take in coordiantes and return the location

Description

Get location from coordinate Take in coordiantes and return the location

Usage

getLocation(location, output = "json", formatted = F, pois = 0,
  limit = 600)

Arguments

location

longtitude and latitude

output

should be "json" or "xml", the type of the result

formatted

logical. whether to return a nice result

pois

whether to return the POI around the location

limit

integer value.If the number of row exceeded limit, function will run in parallel

Value

the corresponding locations

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
## get one location 
location_one = getLocation(c(118.12845, 24.57742))

## vectorization
loc = matrix(c(117.93780, 24.55730, 117.93291, 24.57745, 117.23530, 24.64210, 117.05890, 24.74860), byrow=T, ncol=2)
### json 
location_json = getLocation(loc, output='json')
### get district
library(rjson)
getDistrict = function(x_json){
    x_list = fromJSON(x_json)
    x_list$result$addressComponent$district
}
location_district = sapply(location_json, getDistrict)

### xml
location_xml = getLocation(loc, output='xml')

## formatted
location = getLocation(loc, formatted = T) 
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab