class GeolocationResult implements JsonSerializable (View source)

Constants

ERR_NONE

Error category: no error.

ERR_OTHER

Error category: other/unknown error category.

ERR_NOCURRENTLIBRARY

Error category: no current geolocation library.

ERR_NOCURRENTIPADDRESS

Error category: the IP address of the current client is not available.

ERR_IPNOTPUBLIC

Error category: the IP address is not in the public IP address ranges.

ERR_MISCONFIGURED

Error category: the geolocation library has a wrong configuration.

ERR_NETWORK

Error category: a network error occurred.

ERR_LIBRARYSPECIFIC

Error category: a library-specific error occurred.

Properties

protected int $errorCode

The error category (one of the GeolocationResult::ERR_... constants).

protected string $errorMessage

The error message.

protected Exception|null $innerException

The underlying exception causing the error (if available).

protected string $cityName

The city name.

protected string $stateProvinceCode

The code of the province/state.

protected string $stateProvinceName

The name of the province/state (in American English).

protected string $postalCode

The postal code.

protected string $countryCode

The code of the country (two letter upper case ISO-3166 code).

protected string $countryName

The name of the country (in American English).

protected float|null $latitude

The latitude.

protected float|null $longitude

The longitude.

Methods

setError(int $code, string $message = '', Exception $innerException = null)

Set the error state.

bool
hasError()

Does an error occurred?

int
getErrorCode()

Get the error category (one of the GeolocationResult::ERR_... constants).

string
getErrorMessage()

Get the error message ().

Exception|null
getInnerException()

Get the underlying exception causing the error (if available).

string
getCityName()

Get the city name.

$this
setCityName(string $value)

Set the city name.

string
getStateProvinceCode()

Get the code of the province/state.

$this
setStateProvinceCode(string $value)

Set the code of the province/state.

string
getStateProvinceName()

Get the name of the province/state (in American English).

$this
setStateProvinceName(string $value)

Set the name of the province/state (in American English).

string
getPostalCode()

Get the postal code.

$this
setPostalCode(string $value)

Set the postal code.

string
getCountryCode()

Get the code of the country (two letter upper case ISO-3166 code).

$this
setCountryCode(string $value)

Set the code of the country (two letter upper case ISO-3166 code).

string
getCountryName(bool $resolveFromCodeIfUnavailable = false)

Get the name of the country (in American English).

string
getCountryNameLocalized()

Get the name of the country (in the current language).

$this
setCountryName(string $value)

Set the name of the country (in American English).

float|null
getLatitude()

Get the latitude.

$this
setLatitude(float|null $value)

Set the latitude.

float|null
getLongitude()

Get the longitude.

$this
setLongitude(float|null $value)

Set the longitude.

bool
hasData()

Does this instance contain some geolocalized data?

jsonSerialize()

{@inheritdoc}

Details

setError(int $code, string $message = '', Exception $innerException = null)

Set the error state.

Parameters

int $code

one of the GeolocationResult::ERR_... constants

string $message

the error message

Exception $innerException

the underlying exception causing the error (if available)

bool hasError()

Does an error occurred?

Return Value

bool

int getErrorCode()

Get the error category (one of the GeolocationResult::ERR_... constants).

Return Value

int

return GeolocationResult::ERR_NONE if and only if there's no error

string getErrorMessage()

Get the error message ().

Return Value

string

return an empty string if and only if there's no error

Exception|null getInnerException()

Get the underlying exception causing the error (if available).

Return Value

Exception|null

string getCityName()

Get the city name.

Return Value

string

$this setCityName(string $value)

Set the city name.

Parameters

string $value

Return Value

$this

string getStateProvinceCode()

Get the code of the province/state.

Return Value

string

$this setStateProvinceCode(string $value)

Set the code of the province/state.

Parameters

string $value

Return Value

$this

string getStateProvinceName()

Get the name of the province/state (in American English).

Return Value

string

$this setStateProvinceName(string $value)

Set the name of the province/state (in American English).

Parameters

string $value

Return Value

$this

string getPostalCode()

Get the postal code.

Return Value

string

$this setPostalCode(string $value)

Set the postal code.

Parameters

string $value

Return Value

$this

string getCountryCode()

Get the code of the country (two letter upper case ISO-3166 code).

Return Value

string

$this setCountryCode(string $value)

Set the code of the country (two letter upper case ISO-3166 code).

Parameters

string $value

Return Value

$this

string getCountryName(bool $resolveFromCodeIfUnavailable = false)

Get the name of the country (in American English).

Parameters

bool $resolveFromCodeIfUnavailable

If the Country name is not set, should we try to derive it from the Country code?

Return Value

string

string getCountryNameLocalized()

Get the name of the country (in the current language).

Return Value

string

$this setCountryName(string $value)

Set the name of the country (in American English).

Parameters

string $value

Return Value

$this

float|null getLatitude()

Get the latitude.

Return Value

float|null

$this setLatitude(float|null $value)

Set the latitude.

Parameters

float|null $value

Return Value

$this

float|null getLongitude()

Get the longitude.

Return Value

float|null

$this setLongitude(float|null $value)

Set the longitude.

Parameters

float|null $value

Return Value

$this

bool hasData()

Does this instance contain some geolocalized data?

Return Value

bool

jsonSerialize()

{@inheritdoc}

See also

\JsonSerializable::jsonSerialize()