Learn R Programming

geoChina (version 1.3.0)

revgeocode: Reverse geocode

Description

reverse geocodes a lat/lng location 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

revgeocode(latlng, ics = c("WGS-84", "GCJ-02", "BD-09"), api = c("google",
  "baidu"), key = "", output = c("address", "addressc"),
  messaging = FALSE, time = 0)

Arguments

latlng
a location in latitude/longitude format
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.
api
use Google or Baidu Maps Geocoding API
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.
output
formatted address or formmatted address with address components
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/documentation/geocoding/usage-limits

Value

a data.frame with variables address or detail address components

Details

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

See Also

geocode, 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

Run this code
## Not run: ------------------------------------
# # reverse geocode Beijing Railway Station
# revgeocode(c(39.90358, 116.421), ics = 'WGS-84', api = 'google', 
#            output = 'address')
# revgeocode(c(39.90498, 116.4272), ics = 'GCJ-02', api = 'google', 
#            output = 'address', messaging = TRUE)
# revgeocode(c(39.91103, 116.4337), ics = 'BD-09', api = 'google', 
#            output = 'addressc')
# revgeocode(c(39.91103, 116.4337), ics = 'BD-09', api = 'baidu', 
#            key = 'your baidu maps api key', output = 'address')
# revgeocode(c(39.90498, 116.4272), ics = 'GCJ-02', api = 'baidu', 
#            key = 'your baidu maps api key', output = 'address', messaging = TRUE)
# revgeocode(c(39.90358, 116.421), ics = 'WGS-84', api = 'baidu', 
#            key = 'your baidu maps api key', output = 'addressc')
# # reverse geocode multiple locations
# latlng = data.frame(lat = c(39.99837, 39.98565), lng = c(116.3203, 116.2998))
# revgeocode(latlng, ics = 'WGS-84', api = 'google', output = 'address')
# revgeocode(latlng, ics = 'WGS-84', api = 'google', output = 'address', time = 2)
## ---------------------------------------------

Run the code above in your browser using DataLab