Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class GeoPoint (1.53.0)

Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class GeoPoint.

Represents a geographical point.

Unless specified otherwise, this must conform to the WGS84 standard. Values must be within normalized ranges.

Example:

use Google\Cloud\Core\GeoPoint;

$point = new GeoPoint(37.423147, -122.085015);

Namespace

Google \ Cloud \ Core

Methods

__construct

Create a GeoPoint.

Ints will be converted to floats. Values not passing the is_numeric() check will result in an exception.

Parameters
NameDescription
latitude float|int|null

The GeoPoint Latitude. Note that null is not a generally valid value, and will throw an InvalidArgumentException unless $allowNull is set to true.

longitude float|int|null

The GeoPoint Longitude. Note that null is not a generally valid value, and will throw an InvalidArgumentException unless $allowNull is set to true.

allowNull bool

[optional] If true, null values will be allowed in the constructor only. This switch exists to handle a rare case wherein a geopoint may be empty and is not intended for use from outside the client. Defaults to false.

latitude

Get the latitude

Example:

$latitude = $point->latitude();
Returns
TypeDescription
float|null

setLatitude

Set the latitude

Non-numeric values will result in an exception

Example:

$point->setLatitude(42.279594);
Parameter
NameDescription
latitude int|float

The new latitude

Returns
TypeDescription
Google\Cloud\Core\GeoPoint

longitude

Get the longitude

Example:

$longitude = $point->longitude();
Returns
TypeDescription
float|null

setLongitude

Set the longitude

Non-numeric values will result in an exception.

Example:

$point->setLongitude(-83.732124);
Parameter
NameDescription
longitude float|int

The new longitude value

Returns
TypeDescription
Google\Cloud\Core\GeoPoint

point

Return a GeoPoint

Example:

$point = $point->point();
Returns
TypeDescription
array[LatLng](https://cloud.google.com/datastore/reference/rest/Shared.Types/LatLng)

jsonSerialize

Implement JsonSerializable by representing GeoPoint as a JSON-object:

{
  latitude: 31.778333
  longitude: 35.229722
}
Returns
TypeDescription
object