Geocoder class
google.maps.Geocoder
class
A service for converting between an address and a LatLng
.
Access by calling const {Geocoder} = await google.maps.importLibrary("geocoding")
.
See Libraries in the Maps JavaScript API.
Constructor | |
---|---|
Geocoder |
Geocoder() Parameters: None
Creates a new instance of a Geocoder that sends geocode requests to Google servers. |
Methods | |
---|---|
geocode |
geocode(request[, callback]) Parameters:
Return Value:
Promise<GeocoderResponse> Geocode a request. |
GeocoderRequest interface
google.maps.GeocoderRequest
interface
The specification for a geocoding request to be sent to the Geocoder
.
Properties | |
---|---|
address optional |
Type:
string optional Address to geocode. One, and only one, of address , location and placeId must be supplied. |
bounds optional |
Type:
LatLngBounds|LatLngBoundsLiteral optional LatLngBounds within which to search. Optional. |
componentRestrictions optional |
Type:
GeocoderComponentRestrictions optional 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. |
|
Type:
Array<ExtraGeocodeComputation> optional A list of extra computations which may be used to complete the request. Note: These extra computations may return extra fields on the response. |
fulfillOnZeroResults optional |
Type:
boolean optional Fulfill the promise on a ZERO_RESULT status in the response. This may be desired because even with zero geocoding results there may still be additional response level fields returned. |
language optional |
Type:
string optional A language identifier for the language in which results should be returned, when possible. See the list of supported languages. |
location optional |
Type:
LatLng|LatLngLiteral optional LatLng (or LatLngLiteral ) for which to search. The geocoder performs a reverse geocode. See Reverse Geocoding for more information. One, and only one, of address , location and placeId must be supplied. |
placeId optional |
Type:
string optional The place ID associated with the location. Place IDs uniquely identify a place in the Google Places database and on Google Maps. Learn more about place IDs in the Places API developer guide. The geocoder performs a reverse geocode. See Reverse Geocoding for more information. One, and only one, of address , location and placeId must be supplied. |
region optional |
Type:
string optional Country code used to bias the search, specified as a two-character (non-numeric) Unicode region subtag / CLDR identifier. Optional. See Google Maps Platform Coverage Details for supported regions. |
GeocoderComponentRestrictions interface
google.maps.GeocoderComponentRestrictions
interface
GeocoderComponentRestrictions
represents a set of filters that resolve to a specific area. For details on how this works, see Geocoding Component Filtering.
Properties | |
---|---|
administrativeArea optional |
Type:
string optional Matches all the administrative_area levels . Optional. |
country optional |
Type:
string optional Matches a country name or a two letter ISO 3166-1 country code. Optional. |
locality optional |
Type:
string optional Matches against both locality and sublocality types. Optional. |
postalCode optional |
Type:
string optional Matches postal_code and postal_code_prefix . Optional. |
route optional |
Type:
string optional Matches the long or short name of a route . Optional. |
ExtraGeocodeComputation constants
google.maps.ExtraGeocodeComputation
constants
Extra computations to perform while completing a geocoding request.
Access by calling const {ExtraGeocodeComputation} = await google.maps.importLibrary("geocoding")
.
See Libraries in the Maps JavaScript API.
Constants | |
---|---|
ADDRESS_DESCRIPTORS |
Generate an address descriptor. |
GeocoderStatus constants
google.maps.GeocoderStatus
constants
The status returned by the Geocoder
on the completion of a call to geocode()
. Specify these by value, or by using the constant's name. For example, 'OK'
or google.maps.GeocoderStatus.OK
.
Access by calling const {GeocoderStatus} = await google.maps.importLibrary("geocoding")
.
See Libraries in the Maps JavaScript API.
Constants | |
---|---|
ERROR |
There was a problem contacting the Google servers. |
INVALID_REQUEST |
This GeocoderRequest was invalid. |
OK |
The response contains a valid GeocoderResponse . |
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 this GeocoderRequest . |
GeocoderResponse interface
google.maps.GeocoderResponse
interface
A Geocoder response returned by the Geocoder
containing the list of GeocoderResult
s.
Properties | |
---|---|
results |
Type:
Array<GeocoderResult> The list of GeocoderResult s. |
|
Type:
AddressDescriptor optional A relational description of a location. Includes a ranked set of nearby landmarks and the areas containing the target location. It is only populated for reverse geocoding requests and only when ExtraGeocodeComputation.ADDRESS_DESCRIPTORS is enabled. |
plus_code optional |
Type:
PlacePlusCode optional The plus code associated with the location. |
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 a LatLng
object.
Properties | |
---|---|
address_components |
Type:
Array<GeocoderAddressComponent> An array of GeocoderAddressComponent s |
formatted_address |
Type:
string A string containing the human-readable address of this location. |
geometry |
Type:
GeocoderGeometry A GeocoderGeometry object |
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 about Place IDs in 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 the Address Component Types section of the Developer's Guide. |
|
Type:
|