geocode: Geocode

Description Usage Arguments Value Author(s) See Also Examples

Description

Geocodes (finds latitude and longitude of) a location using the Google Geocoding API. Note: To use Google's Geocoding API, you must first enable the API in the Google Cloud Platform Console. See ?register_google.

Usage

1
2
3
4
5
6
7
8
geocode(location, output = c("latlon", "latlona", "more", "all"),
  source = c("google", "dsk"), force = ifelse(source == "dsk", FALSE,
  TRUE), urlonly = FALSE, override_limit = FALSE,
  nameType = c("long", "short"), ext = "com", inject = "", ...)

mutate_geocode(data, location, ...)

geocodeQueryCheck()

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

"google" for Google (note: "dsk" is defunct)

force

force online query, even if cached (previously downloaded)

urlonly

return only the url?

override_limit

override the current query rate

nameType

in some cases, Google returns both a long name and a short name. this parameter allows the user to specify which to grab.

ext

top level domain (e.g. "com", "co.nz"); helpful for non-US users

inject

character string to add to the url or named character vector of key-value pairs to be injected (e.g. c("a" = "b") get converted to "a=b" and appended to the query)

...

...

data

a data frame or equivalent

Value

If output is "latlon", "latlona", or "more", a tibble (classed data frame). If "all", a list.

Author(s)

David Kahle david.kahle@gmail.com

See Also

http://code.google.com/apis/maps/documentation/geocoding/, https://developers.google.com/maps/documentation/javascript/geocoding, https://developers.google.com/maps/documentation/geocoding/usage-limits

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
## Not run:  requires Google API key, see ?register_google

## basic usage
########################################

# geocoding is most commonly used for addresses
geocode("1600 Amphitheatre Parkway, Mountain View, CA")
geocode("1600 Amphitheatre Parkway, Mountain View, CA", urlonly = TRUE)

# google can also geocode colloquial names of places
geocode("the white house")

# geocode can also accept character vectors of places
geocode(c("the white house", "washington dc"))



## types of output
########################################

geocode("waco texas")
geocode("waco texas", output = "latlona")
geocode("waco texas", output = "more")
str(geocode("waco texas", output = "all"))

geocode(c("waco, texas", "houston, texas"))
geocode(c("waco, texas", "houston, texas"), output = "latlona")
geocode(c("waco, texas", "houston, texas"), output = "all") %>% str(4)



## mutate_geocode
########################################

# mutate_geocode is used to add location columns to an existing dataset
# that has location information

df <- data.frame(
  address = c("1600 Pennsylvania Avenue, Washington DC", "", "houston texas"),
  stringsAsFactors = FALSE
)

mutate_geocode(df, address)
df %>% mutate_geocode(address)


## known issues
########################################

# in some cases geocode finds several locations
geocode("waco city hall")



## End(Not run)

ggmap documentation built on May 1, 2019, 8:22 p.m.