geocode: Geocode

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

View source: R/geocode.R

Description

geocodes an address using Google, Baidu or Gaode 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
geocode(address, output = c("latlng", "latlngc", "latlnga", "all",
  "raw"), api = c("google", "baidu", "gaode"), ocs = c("WGS-84",
  "GCJ-02", "BD-09"), messaging = FALSE, time = 0, use_curl = TRUE,
  idf = TRUE, key = NULL, ...)

Arguments

address

a character vector specifying the locations of interest (e.g., "Tsinghua Univeristy").

output

character, either'latlng', 'latlngc', 'latlnga', 'all' or 'raw'. Default 'latlng'.

  • 'latlng': lat/lng coordinates with location type (Goolge Map)

  • 'latlngc': lat/lng coordinates with location type (Goolge Map) | confidence/precision (Baidu Map)

  • 'latlnga': lat/lng coordinates with formated address and address components (only available for Google and Gaode Map API)

  • 'all': return all the information

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

api

character, the API to use ("google", "baidu" or "gaode"). Default 'google'. When using Baidu or Gaode Maps API, the address must be in Chinese.

ocs

output coordinate systems including 'WGS-84', 'GCJ-02' and 'BD-09', which are the GCSs of Google Earth, Google Map in China and Baidu Map, respectively. For address out of China, ocs is automatically set to 'WGS-84' and other values are igored. Default 'WGS-84'.

messaging

turn messaging on/off. Default FALSE.

time

the time interval to geocode, in seconds. Default value is zero. When you geocode multiple addresses, 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.

idf

logical, whether add an identifier column to the result . If TRUE, address will be applied as an identifier column of the result data.frame. If FALSE, the identifier column will not be generated. You can also manually assign a vector as the identifier. Default TRUE.

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.

...

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)

  • region: a character vector to restrain the scope for a better match. It will be expanded to fit the length of address. You need to refer to the API guide.

  • components: a formatted character vector to restrain the scope for a better match. It will be expanded to fit the length of address. You need to refer to the API guide.

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

  • language: the language in which to return results. Default NULL (the native language).

api == 'baidu'
  • city: a valid Chinese city name to limit the search range

api == 'gaode'
  • city: a valid city character to limit the search range, accepts 4 forms:

    • Chinese city name

    • full pinyin (e.g., "beijing")

    • city code (e.g., "010")

    • adcode (e.g., "110000")

  • batch: Logical, whether apply batch mode. In batch mode, address must be wrapped into character with pipe "|", e.g., "beijing|tianjin".

Value

a data.frame with variables lat/lng or more info

Author(s)

References

See Also

revgeocode(), set_api_key(), geohost(), parse_geocodes()
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
28
29
30
31
32
## Not run: 
aseskit::set_api_key(c("googlemap", "baidumap", "gaodemap"), 
            c(<GOOGLE MAPS API KEY>, <BAIDU MAPS API KEY>,
              <GAODE MAPS API KEY>))

geocode('Tsinghua University', api='google', ocs='GCJ-02')
geocode('Tsinghua University', api='google', ocs='WGS-84',
        messaging=TRUE)
geocode('Beijing railway station', output='latlngc', api='google', 
        ocs='WGS-84')
geocode('Beijing railway station', output='latlnga', api='google', 
        ocs='WGS-84')
geocode(c('Tsinghua University', 'Beijing railway station'), api='google',
        ocs='GCJ-02')
geocode(c('Tsinghua University', 'Beijing railway station'), 
        output='latlngc', api='google', ocs='WGS-84', messaging=TRUE)
geocode(c('Tsinghua University', 'Beijing railway station'), 
        output='latlnga', api='google', ocs='WGS-84', messaging=TRUE)
geocode(c('Tsinghua University', 'Beijing railway station'), 
        output='latlngc', api='google', ocs='WGS-84', messaging=TRUE, 
        time=2)
geocode('Beijing railway station', api='baidu', ocs='BD-09')
geocode('Beijing railway station', api='baidu', ocs='GCJ-02', 
        messaging=TRUE)
geocode('Beijing railway station', output='latlngc', api='baidu', 
        ocs='BD-09')
geocode(c('Tsinghua University', 'Beijing railway station'), api='baidu',
        ocs='BD-09')
geocode(c('Tsinghua University', 'Beijing railway station'), 
        output='latlngc', api='baidu', ocs='WGS-84')

## End(Not run)

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