Address Model
The properties and methods of an Address Model are identical whether you are accessing them via Twig or PHP.
Additional Properties and Methods
The Address Model is an extension of the Location Model. It contains all properties and methods of the Location Model, plus the properties and methods shown below.
You can access lat
and lng
just as easily as street1
and street2
.
# Public Properties
# id
int - ID of the Address.
# elementId
int - Element ID of the element containing the Address.
# siteId
int - Site ID of the site containing the Address.
# fieldId
int - Field ID of the Address field.
# formatted
string - A nicely-formatted single-line interpretation of the address, provided by Google during the initial geocoding.
# raw
array - The original data used to create this Address Model. Contains the full response from the original Google API call.
# name
string - The location's official name. Commonly used for landmarks and business names.
# street1
string - The first line of the street address. Usually contains the street name & number of the location.
# street2
string - The second line of the street address. Usually contains the apartment, unit, or suite number.
# city
string - The city. (aka: town)
# state
string - The state. (aka: province)
# zip
string - The zip code. (aka: postal code)
# neighborhood
string - The neighborhood.
# county
string - The local county. (aka: district)
# country
string - The country. (aka: nation)
Similar sounding, but very different
We recognize that county
and country
are extremely similar words, and apologize on behalf of the English language.
# countryCode
string - The country code.
# placeId
string - The official place_id
as specified by the Google API (opens new window).
# distance
float - Alias for getDistance()
.
# zoom
int - Zoom level of the map as shown in the control panel.
# enabledSubfields
array - Handles of visible subfields.
# Public Methods
# getElement()
Get the corresponding element which contains this Address. It's possible that no element ID exists (for example, if the Address Model was created manually, instead of using data from the database).
# getField()
Get the corresponding field which contains this Address. It's possible that no field ID exists (for example, if the Address Model was created manually, instead of using data from the database).
# getDistance(location = null, units = 'miles')
Calculate the distance between this Address, and a second location. Behaves just as described in the Location Model, pass in a separate location to measure the distance between them.
If the Address was retrieved as part of a proximity search, you can optionally omit all parameters. Skipping both parameters will make the getDistance()
method behave as an alias for the dynamically-calculated distance
property.
When conducting a proximity search, the distance
property is the distance between this Address, and your proximity search target. It will be returned in whatever unit of measurement (miles or kilometers) was specified in the proximity search options.
One Way or the Other
If the Address was not returned in a set of proximity search results, you must functionally declare a second location
. Otherwise, there will be no distance for the method to measure.
# linkToMap(parameters = {})
Identical to parent method, except more data can be extracted from an Address Model.
# linkToDirections(parameters = {}, origin = null)
Identical to parent method, except more data can be extracted from an Address Model.
# isEmpty()
bool - Returns whether all the non-coordinate address fields are empty, or whether they contain any data at all. Specifically looks to see if data exists in any of the following subfields:
street1
street2
city
state
zip
country
# multiline(maxLines = 3)
maxLines
- Maximum number of lines (1-4) allocated to display the address.
# 1
All information will be condensed into a single line. Very similar to formatted
, although the country
value will be omitted here. Other minor formatting differences are also possible, since the formatting is being handled by different sources.
# 2
The street1
and street2
will appear on the first line, everything else (except country
) will appear on the second line.
# 3
If a street2
value exists, it will be given its own line. Otherwise, that line will be skipped.
# 4
Exactly like 3
, with only the addition of the country
value.
# Multiline vs. Formatted
When using the multiline
method, the various subfield components will be explicitly compiled as described in the examples above.
When using the formatted
property, you will get a pre-formatted string which was originally set by the Google API.
The differences between the two are subtle, but they do exist. We can't know how Google compiles each formatted
value, but we have a very specific formula to follow when using multiline
.
Please be mindful of these differences when deciding which to use. When in doubt, you can always just output the model directly as a string.
# Output as a String
{{ address }}
When you output the model directly, it attempts to render the entire address on a single line. This triggers the internal __toString
method, which then does one of the following things...
- If the
formatted
value exists, that will be returned. - Otherwise, it will generate a single line address by using the
multiline(1)
method.
Google Formatted Preferred
The formatted
value will be preferred, because it was supplied by Google as a pre-compiled string. However, the end result of multiline(1)
should (theoretically) be similar enough for a reasonable fallback.