Location
Module to generate addresses and locations.Overview
For a typical street address for a locale, use {{$location.streetAddress}}
, {{$location.city}}
, {{$location.state}}
, and {{$location.zipCode}}
. Most locales provide localized versions for a specific country.If you need latitude and longitude coordinates, use {{$location.latitude}}
and {{$location.longitude}}
, or {{$location.nearbyGPSCoordinateLatitude}}
for a latitude/longitude near a given location.For a random country, you can use {{$location.country}}
or {{$location.countryCode}}
.
buildingNumber#
Generates a random building number.
cardinalDirection#
Returns a random cardinal direction.Name | Type | Default | Description |
---|
abbreviated | boolean | false | If true this will return abbreviated directions (N, E, etc). Otherwise this will return the long name. |
city#
Generates a random localized city name.
country#
Returns a random country name.
countryCode#
Returns a random country name.Name | Type | Default | Description |
---|
variant | 'alpha-2' |'alpha-3' | 'numeric' | 'alpha-2' | The code to return. Can be either 'alpha-2' (two-letter code), 'alpha-3' (three-letter code) or 'numeric' (numeric code). |
direction#
Returns a random direction .Name | Type | Default | Description |
---|
abbreviated | boolean | false | If true this will return abbreviated directions (NW, E, etc). Otherwise this will return the long name. |
latitude#
Generates a random latitude.Name | Type | Default | Description |
---|
max | number | 90 | The upper bound for the latitude to generate. |
min | number | -90 | The lower bound for the latitude to generate. |
precision | number | 4 | The number of decimal points of precision for the latitude. |
longitude#
Generates a random longitude.Name | Type | Default | Description |
---|
max | number | 90 | The upper bound for the longitude to generate. |
min | number | -90 | The lower bound for the longitude to generate. |
precision | number | 4 | The number of decimal points of precision for the longitude. |
nearbyGPSCoordinate#
Generates a random GPS coordinate within the specified radius from the given coordinate.The original faker.location.nearbyGPSCoordinate()
method has been refined into two more precise variables:{{$location.nearbyGPSCoordinateLatitude}}
: Generates an Latitude within the specified radius from the given coordinate.
{{$location.nearbyGPSCoordinateLongitude}}
: Generates an Longitude within the specified radius from the given coordinate.
Name | Type | Default | Description |
---|
isMetric | boolean | false | If true assume the radius to be in kilometers. If false for miles. |
latitude | number | | The original latitude to get a new coordinate close to. |
longitude | number | | The original longitude to get a new coordinate close to. |
radius | number | 10 | The maximum distance from the given coordinate to the new coordinate. |
Returns: [latitude: number, longitude: number]
ordinalDirection#
Returns a random ordinal direction (northwest, southeast, etc).Name | Type | Default | Description |
---|
abbreviated | boolean | false | If true this will return abbreviated directions (NW, SE, etc). Otherwise this will return the long name. |
secondaryAddress#
Generates a random localized secondary address. This refers to a specific location at a given address such as an apartment or room number.
state#
Returns a random localized state, or other equivalent first-level administrative entity for the locale's country such as a province or region. Generally, these are the ISO 3166-2 subdivisions for a country. If a locale doesn't correspond to one specific country, the method may return ISO 3166-2 subdivisions from one or more countries that uses that language. For example, the ar
locale includes subdivisions from Arabic-speaking countries, such as Tunisia, Algeria, Syria, Lebanon, etc. For historical compatibility reasons, the default en
locale only includes states in the United States (identical to en_US
). However, you can use other English locales, such as en_IN
, en_GB
, and en_AU
, if needed.Name | Type | Default | Description |
---|
abbreviated | boolean | false | If true this will return abbreviated first-level administrative entity names. Otherwise this will return the long name. |
street#
Generates a random localized street name.
streetAddress#
Generates a random localized street address.Name | Type | Default | Description |
---|
useFullAddress | boolean | | When true this will generate a full address. Otherwise it will just generate a street address. |
| | | |
timeZone#
Returns a random IANA time zone relevant to this locale.The returned time zone is tied to the current locale.
zipCode#
Generates random zip code from specified format. If format is not specified, the locale's zip format is used.Name | Type | Default | Description |
---|
format | string | | WThe optional format used to generate the zip code. This won't be used if the state option is specified. |
Modified at 2024-08-30 10:46:00