geocode: Geocode

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

Description

geocodes an address using Google or Baidu Maps Geocoding API. Note that in most cases by using this function you are agreeing to the Google Maps API Terms of Service at https://developers.google.com/maps/terms or the Baidu Maps API Terms of Use at http://developer.baidu.com/map/law.htm.

Usage

1
2
3
geocode(address, api = c("google", "baidu"), key = "",
  ocs = c("WGS-84", "GCJ-02", "BD-09"), output = c("latlng", "latlngc",
  "latlnga"), messaging = FALSE, time = 0)

Arguments

address

a character vector specifying a location of interest (e.g., "Beijing Railway Station").

api

use Google or Baidu Maps Geocoding API. When using Baidu Maps Geocoding API, the address must be in Chinese.

key

an API key must be provided when calling Baidu Maps Geocoding API. When calling Google Maps Geocoding API, you'd better provide an API key, though it is not necessary.

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.

output

lat/lng coordinates or lat/lng coordinates with location type (Goolge Map) | confidence #' (Baidu Map) or lat/lng coordinates with formated address and address components (only available for #' Google Map API).

messaging

turn messaging on/off. The default value is 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/documentation/geocoding/usage-limits

Details

note that the google maps api limits to 2,500 free requests per day and 50 requests per second.

Value

a data.frame with variables lat/lng or lat/lng/conf

Author(s)

Jun Cai (cai-j12@mails.tsinghua.edu.cn), PhD candidate from Department of Earth System Science, Tsinghua University

See Also

revgeocode, geohost.

Google Maps API at https://developers.google.com/maps/documentation/geocoding/ and Baidu Maps API at http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding

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
## Not run: 
geocode('Beijing Railway Station', api = 'google', ocs = 'GCJ-02')
geocode('Beijing Railway Station', api = 'google', ocs = 'WGS-84', 
        messaging = TRUE)
geocode('Beijing Railway Station', api = 'google', ocs = 'WGS-84', 
        output = 'latlngc')
geocode('Beijing Railway Station', api = 'google', ocs = 'WGS-84', 
        output = 'latlnga')
geocode(c('Beijing Railway Station', 'Beijingxi Railway Station'), api = 'google', 
        ocs = 'GCJ-02')
geocode(c('Beijing Railway Station', 'Beijingxi Railway Station'), api = 'google', 
        ocs = 'WGS-84', output = 'latlngc', messaging = TRUE)
geocode(c('Beijing Railway Station', 'Beijingxi Railway Station'), api = 'google', 
        ocs = 'WGS-84', output = 'latlnga', messaging = TRUE)
geocode(c('Beijing Railway Station', 'Beijingxi Railway Station'), api = 'google', 
        ocs = 'WGS-84', output = 'latlngc', messaging = TRUE, time = 2)
geocode('Beijing Railway Station', api = 'baidu', key = 'your baidu maps api key', 
ocs = 'BD-09')
geocode('Beijing Railway Station', api = 'baidu', key = 'your baidu maps api key', 
ocs = 'GCJ-02', messaging = TRUE)
geocode('Beijing Railway Station', api = 'baidu', key = 'your baidu maps api key', 
ocs = 'BD-09', output = 'latlngc')
geocode(c('Beijing Railway Station', 'Beijingxi Railway Station'), api = 'baidu', 
key = 'your baidu maps api key', ocs = 'BD-09')
geocode(c('Beijing Railway Station', 'Beijingxi Railway Station'), api = 'baidu', 
key = 'your baidu maps api key', ocs = 'WGS-84', output = 'latlngc')

## End(Not run)

caijun/geoChina documentation built on May 13, 2019, 11 a.m.