revgeocode: Reverse geocode

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/revgeocode.R

Description

Reverse geocodes a lat/lng location using Google or Baidu Maps API. Note that in most cases by using this function you are agreeing to the Google Maps API Terms of Service at https://cloud.google.com/maps-platform/terms/, the Baidu Maps API Terms of Use at http://lbsyun.baidu.com/index.php?title=open/question or the Gaode Maps API Terms of Use at https://lbs.amap.com/faq/top/notice.
Note that geocoding service may cause charges. Take care of our app key and check the quota carefully.

Usage

1
2
3
4
revgeocode(latlng, ics = c("WGS-84", "GCJ-02", "BD-09"),
  output = c("address", "addressc", "all", "raw"), api = c("google",
  "baidu", "gaode"), messaging = FALSE, time = 0, use_curl = TRUE,
  key = NULL, auto_fix_latlng = TRUE, ...)

Arguments

latlng

a location in latitude/longitude format, either a vector, list, matrix or a data.frame. The function will automatically identify the inputs and convert it to a data.frame [lat, lng] to proceed on.

vector: only extract the first two elements

c(30, 100, ...) ==> data.frame(lat=30, lon=100)

matrix: automatically identify the structure

matrix(c(30, 20, 40, 100, 110, 90), ncol=2) ==> data.frame(lat=c(30, 20, 40), lon=c(100, 110, 90))

list: the lat and lon vectors are nested inside the list

list(c(30, 20, 40), c(100, 110, 90)) ==> data.frame(lat=c(30, 20, 40), lon=c(100, 110, 90))

data.frame: only extract the first two columns

data.frame(v1=c(30, 20), v2=c(100, 110), v3=...) ==> data.frame(lat=c(30, 20), lon=c(100, 110))

ics

the coordinate system of inputing location, including 'WGS-84', 'GCJ-02' and 'BD-09', which are the GCSs of Google Earth, Google Map in China and Baidu Map, respectively. For location out of China, ics is automatically set to 'WGS-84' and other values are ignored.

output

character, either 'address', 'addressc', 'all' or 'raw'. Default 'address'.

  • 'address': formatted address

  • 'addressc': formmatted address with address components

  • 'all': all information

  • 'raw': return the raw data parsed from JSON by fromJSON(). You will then need to parse the data on your own.

api

use 'google', 'baidu' or 'gaode' maps api

messaging

turn messaging on/off. The default value is FALSE.

time

the time interval to revgeocode, in seconds. Default value is zero. When you revgeocode multiple locations, set a proper time interval to avoid exceeding usage limits. For details see https://developers.google.com/maps/premium/usage-limits

use_curl

logical, whether use curl (TRUE) or url (FALSE) to create the connection when calling the APIs. Default TRUE. The avialability of curl dependes on your network conditions.

key

an api key must be provided when calling the Maps APIs. Default NULL, which indicates that the function will search for cache. If no match is found, a GUI wizard will be launched to enter the api key. If the API does not call for a key, set it to NA.

auto_fix_latlng

logical, if the latlng data is of the opposite order, whether to let the function automatically fix it. Default TRUE.

...

other arguments to pass to the function, dependent on api.

api == 'google'
  • client and signature instead of key for higher security (if you have a premium account)

  • language the language in which to return results, the supported languages refers to https://developers.google.com/maps/faq#languagesupport

  • result_type a filter of one or moree address types (separated by a pipe '|'), e.g., 'country|political'.

  • location_type a filter of one or moree address types (separated by a pipe '|'), e.g., 'ROOFTOP|APPROXIMATE'.

  • name_type: either 'long' or 'short' indicating long_name or short_name is returned. Default 'long'.

api == 'baidu'
  • pois: 1 or 0. whether callback surrounding pois (1=Yes, 0=No). You will need to apply for special service access when calling pois outside China.

  • radius: the radius for calling back pois. 0-1000 (m).

  • extensions_road: callback 3 streets near the spot when set to TRUE.

  • extensions_town: callback info of town when set to TRUE.

  • language: 'local' or short-form of languages, e.g., 'en', 'zh-CN'. You will need to apply for special service access when using multi-language functionality.

  • langauge_auto: whether auto fill the admin area (1=Yes, 0=No). You will need to apply for special service access when using multi-language functionality.

  • latest_admin: whether get the latest administrative area info (1=Yes, 0=No).

api == 'gaode'
  • extensions: return basic info ('base') or base+additional info ('all'). When extensions='all', some more parameters will take effect:

    • poitype: one or more POI type codes (separated by a pipe '|'). The valid POI type codes refers to https://lbs.amap.com/api/webservice/download. It will not take effect when applying batch mode (multiple latlngs are provided).

    • radius: the radius for calling back pois. 0-3000 (m).

    • roadlevel: return all the roads (0) or main roads only (1)

    • homeorcorp: order the callback pois,

      • 0: do not intervene the order of the pois.

      • 1: home-related pois are prioritized.

      • 2: coorporate-related pois are prioritized.

Value

a data.frame with variables address or detail address components

Author(s)

References

See Also

geocode(), set_api_key(), geohost().
Refer to transform_coord function family to read the details about argument y, which is consistent with latlng.
synthesize_googlemap_api(), synthesize_baidumap_api(), synthesize_gaodemap_api()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Not run: 
set_api_key(c("googlemap", "baidumap", "gaodemap"), 
            c(<GOOGLE MAPS API KEY>, <BAIDU MAPS API KEY>,
              <GAODE MAPS API KEY>))

# reverse geocode Beijing railway station
revgeocode(c(39.90105, 116.42079), ics = 'WGS-84', output = 'address', 
           api = 'google')
revgeocode(c(39.90245, 116.42703), ics = 'GCJ-02', output = 'address', 
           api = 'google', messaging = TRUE)
revgeocode(c(39.90851, 116.43351), ics = 'BD-09', output = 'addressc', 
           api = 'google',)
revgeocode(c(39.90851, 116.43351), ics = 'BD-09', output = 'address',
           api = 'baidu')
revgeocode(c(39.90245, 116.42703), ics = 'GCJ-02', output = 'address', 
           api = 'baidu',messaging = TRUE)
revgeocode(c(39.90105, 116.42079), ics = 'WGS-84', output = 'addressc',
           api = 'baidu')

# reverse geocode multiple locations
latlng = data.frame(lat = c(39.99837, 39.98565), 
                    lng = c(116.3203, 116.2998))
revgeocode(latlng, ics = 'WGS-84', output = 'all', api = 'google')
revgeocode(latlng, ics = 'WGS-84', output = 'all', api = 'google', 
           time = 2)

## End(Not run)

madlogos/asesgeo documentation built on Aug. 9, 2019, 9:53 a.m.