==Geocode Function==
The official arguments for the function are the following:
setof record geocode(varchar address, integer max_results=10, geometry restrict_region=NULL, norm_addy OUT addy, geometry OUT geomout, integer OUT rating);
The arguments of interest are address, where you simply submit a string, and max_results, which restricts the number of geocoding attempts per address. The geocoder makes multiple guesses to the location of an address, and returns the best guesses in order. If you want multiple guesses to a specific address, then specify max_results to be more than 1.
===Single Address===
An example query for a single address is:
SELECT g.rating, ST_X(g.geomout) As lon, ST_Y(g.geomout) As lat,
(addy).address As stno, (addy).streetname As street,
(addy).streettypeabbrev As styp, (addy).location As city, (addy).stateabbrev As st,(addy).zip
FROM geocode('75 State Street, Boston MA 02109', 1) As g;
rating -- This is an integer that determines the confidence in the resulting geocode. The closer to 0, the more confident the guess.
ST_X(g.geomout) -- This retrieves the longitude coordinate of the point.
ST_Y(g.geomout) -- This retrieves the latitude corodinate of the point.
addy -- In general, addy is a normalized address resulting from the input address.
(addy).address -- The number of the address (Ex: "75" Blabla rd.)
(addy).streetname -- The name of the street (Ex: 75 "Blabla" rd.)
(addy).streettypeabbrev -- The abbreviation of the street (Ex: 75 blabla "rd")
(addy).location -- The city location of the address.
(addy).stateabbrev -- The state abbreviation.
(addy).zip -- The zipcode of the address.
The output of the query above would be:
rating | lon | lat | stno | street | styp | city | st | zip
--------+-------------------+----------------+------+--------+------+--------+----+-------
0 | -71.0557505845646 | 42.35897920691 | 75 | State | St | Boston | MA | 02109