Address Types
The GeocodeAddressTypes
object is a helper object to test the geocode address component address types.
Instead of testing the types
array against string values, you can call a method in the GeocodeAddressTypes
class to test the address type.
Example usage
Below is an example of how you could interact with this object when working with geocode results.
const geocoder = G.geocode({
address: '221 B Baker St, London, England'
});
geocoder.fetch()
.then((response) => {
if (response.hasResults()) {
const result = response.getFirst();
response.getAddressComponents().forEach((component) => {
const types = component.getTypes();
if (types.isStreetNumber()) {
console.log('This is a street number');
} else if (types.isCity()) {
console.log('This is a city, town, or locality');
}
});
}
})
.catch((error) => {
console.error('Error: ', error);
});
Methods
getTypes
getTypes(): string[]
Get the array of address types. This allows you to access the raw data returned from Google.
const typeValues = types.getTypes();
isAdministrativeAreaLevel1
isAdministrativeAreaLevel1(): boolean
Returns if the address is an administrative area level 1. This is the highest level of administrative area below the country level. In the United States, these administrative levels are states.
if (types.isAdministrativeAreaLevel1()) {
// Do something
}
isAdministrativeAreaLevel2
isAdministrativeAreaLevel2(): boolean
Returns if the address is an administrative area level 2. Within the United States this would be a county.
if (types.isAdministrativeAreaLevel2()) {
// Do something
}
isAdministrativeAreaLevel3
isAdministrativeAreaLevel3(): boolean
Returns if the address is an administrative area level 3. This is a minor civil division.
if (types.isAdministrativeAreaLevel3()) {
// Do something
}
isAdministrativeAreaLevel4
isAdministrativeAreaLevel4(): boolean
Returns if the address is an administrative area level 4. This is a minor civil division.
if (types.isAdministrativeAreaLevel4()) {
// Do something
}
isAdministrativeAreaLevel5
isAdministrativeAreaLevel5(): boolean
Returns if the address is an administrative area level 5. This is a minor civil division.
if (types.isAdministrativeAreaLevel5()) {
// Do something
}
isAdministrativeAreaLevel6
isAdministrativeAreaLevel6(): boolean
Returns if the address is an administrative area level 6. This is a minor civil division.
if (types.isAdministrativeAreaLevel6()) {
// Do something
}
isAdministrativeAreaLevel7
isAdministrativeAreaLevel7(): boolean
Returns if the address is an administrative area level 7. This is a minor civil division.
if (types.isAdministrativeAreaLevel7()) {
// Do something
}
isAirport
isAirport(): boolean
Returns if the address is an airport.
if (types.isAirport()) {
// Do something
}
isBusStation
isBusStation(): boolean
Returns if the address is a bus station or bus stop.
if (types.isBusStation()) {
// Do something
}
isCity
isCity(): boolean
Returns if the address is a town or city. This is an alias for isLocality.
if (types.isCity()) {
// Do something
}
isColloquialArea
isColloquialArea(): boolean
Returns if the address is a commonly used alternative name for the entity.
if (types.isColloquialArea()) {
// Do something
}
isCountry
isCountry(): boolean
Returns if the address is a country.
if (types.isCountry()) {
// Do something
}
isCounty
isCounty(): boolean
Returns if the address is a county. This is an alias for isAdministrativeAreaLevel2.
if (types.isCounty()) {
// Do something
}
isEstablishment
isEstablishment(): boolean
Returns if the address is a place that hasn't yet been categorized.
if (types.isEstablishment()) {
// Do something
}
isFloor
isFloor(): boolean
Returns if the address is a floor of a building.
if (types.isFloor()) {
// Do something
}
isIntersection
isIntersection(): boolean
Returns if the address is a major intersection, usually of two major roads.
if (types.isIntersection()) {
// Do something
}
isLandmark
isLandmark(): boolean
Returns if the address is a landmark.
if (types.isLandmark()) {
// Do something
}
isLocality
isLocality(): boolean
Returns if the address is a locality (i.e. town or city).
if (types.isLocality()) {
// Do something
}
isNaturalFeature
isNaturalFeature(): boolean
Returns if the address is a prominent natural feature.
if (types.isNaturalFeature()) {
// Do something
}
isNeighborhood
isNeighborhood(): boolean
Returns if the address is a neighborhood.
if (types.isNeighborhood()) {
// Do something
}
isPlusCode
isPlusCode(): boolean
Returns if the address is a plus code. See the Plus Codes website for more information about plus codes.
if (types.isPlusCode()) {
// Do something
}
isPark
isPark(): boolean
Returns if the address is a park.
if (types.isPark()) {
// Do something
}
isParking
isParking(): boolean
Returns if the address is a parking lot.
if (types.isParking()) {
// Do something
}
isPointOfInterest
isPointOfInterest(): boolean
Returns if the address is a point of interest.
if (types.isPointOfInterest()) {
// Do something
}
isPolitical
isPolitical(): boolean
Returns if the address is a political entity. This would usually be some type of civil administration.
if (types.isPolitical()) {
// Do something
}
isPostBox
isPostBox(): boolean
Returns if the address is a specific post office box.
if (types.isPostBox()) {
// Do something
}
isPostalCode
isPostalCode(): boolean
Returns if the address is a postal code.
if (types.isPostalCode()) {
// Do something
}
isPostalTown
isPostalTown(): boolean
Returns if the address is a grouping of geographic areas.
if (types.isPostalTown()) {
// Do something
}
isPremise
isPremise(): boolean
Returns if the address is a named location, usually a building or collection of buildings with a common name.
if (types.isPremise()) {
// Do something
}
isRoom
isRoom(): boolean
Returns if the address is a room of a building.
if (types.isRoom()) {
// Do something
}
isRoute
isRoute(): boolean
Returns if the address is a named route (such as "US 101").
if (types.isRoute()) {
// Do something
}
isState
isState(): boolean
Returns if the address is a state or province. This is an alias for isAdministrativeAreaLevel1.
if (types.isState()) {
// Do something
}
isStreetAddress
isStreetAddress(): boolean
Returns if the address is a street address.
if (types.isStreetAddress()) {
// Do something
}
isStreetNumber
isStreetNumber(): boolean
Returns if the address is a precise street number.
if (types.isStreetNumber()) {
// Do something
}
isSubLocality
isSubLocality(): boolean
Returns if the address is a sublocality.
if (types.isSubLocality()) {
// Do something
}
isSubLocalityLevel1
isSubLocalityLevel1(): boolean
Returns if the address is a sublocality level 1.
if (types.isSubLocalityLevel1()) {
// Do something
}
isSubLocalityLevel2
isSubLocalityLevel2(): boolean
Returns if the address is a sublocality level 2.
if (types.isSubLocalityLevel2()) {
// Do something
}
isSubLocalityLevel3
isSubLocalityLevel3(): boolean
Returns if the address is a sublocality level 3.
if (types.isSubLocalityLevel3()) {
// Do something
}
isSubLocalityLevel4
isSubLocalityLevel4(): boolean
Returns if the address is a sublocality level 4.
if (types.isSubLocalityLevel4()) {
// Do something
}
isSubLocalityLevel5
isSubLocalityLevel5(): boolean
Returns if the address is a sublocality level 5.
if (types.isSubLocalityLevel5()) {
// Do something
}
isSubPremise
isSubPremise(): boolean
Returns if the address is a subpremise. This is the next level below a premise, usually a single building in a collection of buildings with a common name.
if (types.isSubPremise()) {
// Do something
}
isTown
isTown(): boolean
Returns if the address is a town or city. This is an alias for isLocality.
if (types.isTown()) {
// Do something
}
isTrainStation
isTrainStation(): boolean
Returns if the address is a train station.
if (types.isTrainStation()) {
// Do something
}
isTransitStation
isTransitStation(): boolean
Returns if the address is a transit station.
if (types.isTransitStation()) {
// Do something
}