Geocoder

Geocoder class

google.maps.Geocoder class

A service for converting between an address and aLatLng.

Access by callingconst {Geocoder} = await google.maps.importLibrary( "geocoding" ).SeeLibraries in the Maps JavaScript API.

Geocoder
Geocoder()
Parameters:None
Creates a new instance of aGeocoderthat sends geocode requests to Google servers.
geocode
geocode(request[, callback])
Parameters:
Geocode a request.

GeocoderRequest interface

google.maps.GeocoderRequest interface

The specification for a geocoding request to be sent to theGeocoder.

addressoptional
Type:stringoptional
Address to geocode. One, and only one, ofaddress,locationandplaceIdmust be supplied.
boundsoptional
LatLngBoundswithin which to search. Optional.
componentRestrictionsoptional
Components are used to restrict results to a specific area. A filter consists of one or more of:route,locality,administrativeArea,postalCode,country.Only the results that match all the filters will be returned. Filter values support the same methods of spelling correction and partial matching as other geocoding requests. Optional.
languageoptional
Type:stringoptional
A language identifier for the language in which results should be returned, when possible. See thelist of supported languages.
locationoptional
Type:LatLng|LatLngLiteraloptional
LatLng(orLatLngLiteral) for which to search. The geocoder performs a reverse geocode. SeeReverse Geocodingfor more information. One, and only one, ofaddress,locationandplaceIdmust be supplied.
placeIdoptional
Type:stringoptional
The place ID associated with the location. Place IDs uniquely identify a place in the Google Places database and on Google Maps. Learn more aboutplace IDsin the Places API developer guide. The geocoder performs a reverse geocode. SeeReverse Geocodingfor more information. One, and only one, ofaddress,locationandplaceIdmust be supplied.
regionoptional
Type:stringoptional
Country code used to bias the search, specified as a two-character (non-numeric) Unicode region subtag / CLDR identifier. Optional. SeeGoogle Maps Platform Coverage Detailsfor supported regions.

GeocoderComponentRestrictions interface

google.maps.GeocoderComponentRestrictions interface

GeocoderComponentRestrictionsrepresents a set of filters that resolve to a specific area. For details on how this works, seeGeocoding Component Filtering.

administrativeAreaoptional
Type:stringoptional
Matches all theadministrative_area levels.Optional.
countryoptional
Type:stringoptional
Matches a country name or a two letter ISO 3166-1 country code. Optional.
localityoptional
Type:stringoptional
Matches against bothlocalityandsublocalitytypes. Optional.
postalCodeoptional
Type:stringoptional
Matchespostal_codeandpostal_code_prefix.Optional.
routeoptional
Type:stringoptional
Matches the long or short name of aroute.Optional.

GeocoderStatus constants

google.maps.GeocoderStatus constants

The status returned by theGeocoderon the completion of a call togeocode().Specify these by value, or by using the constant's name. For example,'OK'orgoogle.maps.GeocoderStatus.OK.

Access by callingconst {GeocoderStatus} = await google.maps.importLibrary( "geocoding" ).SeeLibraries in the Maps JavaScript API.

ERROR There was a problem contacting the Google servers.
INVALID_REQUEST ThisGeocoderRequestwas invalid.
OK The response contains a validGeocoderResponse.
OVER_QUERY_LIMIT The webpage has gone over the requests limit in too short a period of time.
REQUEST_DENIED The webpage is not allowed to use the geocoder.
UNKNOWN_ERROR A geocoding request could not be processed due to a server error. The request may succeed if you try again.
ZERO_RESULTS No result was found for thisGeocoderRequest.

GeocoderResponse interface

google.maps.GeocoderResponse interface

A Geocoder response returned by theGeocodercontaining the list ofGeocoderResults.

results
The list ofGeocoderResults.

GeocoderResult interface

google.maps.GeocoderResult interface

A single geocoder result retrieved from the geocode server. A geocode request may return multiple result objects. Note that though this result is "JSON-like," it is not strictly JSON, as it indirectly includes aLatLngobject.

address_components
An array ofGeocoderAddressComponents
formatted_address
Type:string
A string containing the human-readable address of this location.
geometry
AGeocoderGeometryobject
place_id
Type:string
The place ID associated with the location. Place IDs uniquely identify a place in the Google Places database and on Google Maps. Learn more aboutPlace IDsin the Places API developer guide.
types
Type:Array<string>
An array of strings denoting the type of the returned geocoded element. For a list of possible strings, refer to theAddress Component Typessection of the Developer's Guide.
partial_matchoptional
Type:booleanoptional
Whether the geocoder did not return an exact match for the original request, though it was able to match part of the requested address. If an exact match, the value will beundefined.
plus_codeoptional
Type:PlacePlusCodeoptional
The plus code associated with the location.
postcode_localitiesoptional
Type:Array<string>optional
An array of strings denoting all the localities contained in a postal code. This is only present when the result is a postal code that contains multiple localities.

GeocoderAddressComponent interface

google.maps.GeocoderAddressComponent interface

A single address component within aGeocoderResult.A full address may consist of multiple address components.

long_name
Type:string
The full text of the address component
short_name
Type:string
The abbreviated, short text of the given address component
types
Type:Array<string>
An array of strings denoting the type of this address component. A list of valid types can be foundhere

GeocoderGeometry interface

google.maps.GeocoderGeometry interface

Geometry information about thisGeocoderResult

location
Type:LatLng
The latitude/longitude coordinates of this result
location_type
The type of location returned inlocation
viewport
The bounds of the recommended viewport for displaying thisGeocoderResult
boundsoptional
Type:LatLngBoundsoptional
The precise bounds of thisGeocoderResult,if applicable

GeocoderLocationType constants

google.maps.GeocoderLocationType constants

Describes the type of location returned from a geocode. Specify these by value, or by using the constant's name. For example,'ROOFTOP'orgoogle.maps.GeocoderLocationType.ROOFTOP.

Access by callingconst {GeocoderLocationType} = await google.maps.importLibrary( "geocoding" ).SeeLibraries in the Maps JavaScript API.

APPROXIMATE The returned result is approximate.
GEOMETRIC_CENTER The returned result is the geometric center of a result such a line (e.g. street) or polygon (region).
RANGE_INTERPOLATED The returned result reflects an approximation (usually on a road) interpolated between two precise points (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address.
ROOFTOP The returned result reflects a precise geocode.