Learn R Programming

ggmap (version 2.5.2)

geocode: Geocode

Description

Geocodes a location (find latitude and longitude) using either (1) the Data Science Toolkit (http://www.datasciencetoolkit.org/about) or (2) Google Maps. Note that when using Google you are agreeing to the Google Maps API Terms of Service at https://developers.google.com/maps/terms.

Usage

geocode(location, output = c("latlon", "latlona", "more", "all"),
  source = c("dsk", "google"), messaging = FALSE, sensor = FALSE,
  override_limit = FALSE, client = "", signature = "",
  nameType = c("long", "short"), data)

geocodeQueryCheck(userType = "free")

Arguments

location
a character vector of street addresses or place names (e.g. "1600 pennsylvania avenue, washington dc" or "Baylor University")
output
amount of output, "latlon", "latlona", "more", or "all"
source
"dsk" for Data Science Toolkit or "google" for Google
messaging
turn messaging on/off
sensor
whether or not the geocoding request comes from a device with a location sensor
override_limit
override the current query count (.GoogleGeocodeQueryCount)
client
client ID for business users, see https://developers.google.com/maps/documentation/business/webservices/auth
signature
signature for business users, see https://developers.google.com/maps/documentation/business/webservices/auth
nameType
in some cases, Google returns both a long name and a short name. this parameter allows the user to specify which to grab.
data
deprecated in 2.5, use mutate_geocode
userType
User type, "free" or "business"

Value

  • If output is "latlon", "latlona", or "more", a data frame. If all, a list.

Details

Note that the Google Maps api limits to 2500 queries a day. Use geocodeQueryCheck to determine how many queries remain.

See Also

mutate_geocode, http://code.google.com/apis/maps/documentation/geocoding/

Examples

Run this code
# Server response can be slow; this cuts down check time.

# types of input
geocode("houston texas")
geocode("baylor university", source = "google") # see known issues below
geocode("1600 pennsylvania avenue, washington dc", source = "google")
geocode("the white house", source = "google")
geocode(c("baylor university", "salvation army waco"), source = "google")


# types of output
geocode("houston texas", output = "latlona")
geocode("houston texas", output = "more", source = "google")
geocode("Baylor University", output = "more", source = "google")
str(geocode("Baylor University", output = "all", source = "google"))


# see how many requests we have left with google
geocodeQueryCheck()



# known issues :
# (1) source = "dsk" can't reliably geocode colloquial place names
geocode("city hall houston")
geocode("rice university")

Run the code above in your browser using DataLab