Google created the Google Maps API, or application programming interface, to allow you to create a program that can interact with Google Maps to retrieve information and present it to your program's end user. Although the Google Maps API does not have a specific method for validating addresses, Google's Geocoding API provides information that allows you to determine if Google has information about a specific address.
Google's Geocoding API accepts addresses in a human readable form and returns information about that address including its latitude and longitude. If you enter a valid address, Google will return an exact latitude and longitude location. If you enter an invalid address, Google will also return a location range in which the address would be contained if it existed. Google limits usage of its Geocoding API to 2,500 requests per day. The API can only be used if you display the results on a Google map.
Google accepts geocoding requests over HTTP and returns a response in an XML or JSON format. The following is the proper syntax for a geocoding request:
You must replace "Output" with either "JSON" or "XML." Replace "Parameters" with the address that you want to validate and an indicator that the device sending the request does not have a location sensor. For example, the following request would return a JSON file containing information about the address 1600 Pennsylvania Avenue in Washington, D.C.:
Google will return a formatted XML or JSON file containing information about the address that you provided. The results array within the file will contain a listing of valid results for your search. In most cases, this result will only include a single result. Within the geometry array, you will find information about the returned location. The location_type field indicates what type of location information Google has for the address that you provided. If Google recognizes the address as a valid address it will return "ROOFTOP" as the location_type. If Google does not recognize the address it will also return a bounds field within the geometry field. Bounds contains latitude and longitude values that represent a bounding box that would contain the address if it existed. Google may also return a partial_match field if it could not identify the address that you provided as a valid address.
If Google cannot identify the address that you provided, you can use the information that Google provides to find the nearest valid address to the location where the invalid address would be located. The location field within the geometry field in the results contains Google's best guess about the location of the invalid address that you provided. If you pass this latitude and longitude into a geocoding request in place of an address, Google will return the closest actual address to that location or a range of addresses in that region. For example, Google returns 41.8925030, -87.62674989999999 as the closest latitude and longitude to the nonvalid address: 30 East Ohio, Chicago IL. If you request that latitude and longitude from Google as follows:
Then it returns the nearest actual address: 600 N Wabash Ave, Chicago IL.