GoogleMapsGeocoder

GoogleMapsGeocoder
in package

A PHP wrapper for the Google Maps Geocoding API v3.

Tags
author

Justin Stayton

copyright

Copyright 2015 by Justin Stayton

license

https://github.com/jstayton/Miner/blob/master/LICENSE-MIT MIT

link
https://developers.google.com/maps/documentation/geocoding/intro
version
2.4.0

Table of Contents

EQUATOR_LAT_DEGREE_IN_MILES  = 69.172
Helps calculate a more realistic bounding box by taking into account the curvature of the earth's surface.
FORMAT_JSON  = "json"
JSON response format.
FORMAT_XML  = "xml"
XML response format.
LOCATION_TYPE_APPROXIMATE  = "APPROXIMATE"
Returned result is approximate.
LOCATION_TYPE_CENTER  = "GEOMETRIC_CENTER"
Returned result is the geometric center of a polyline (i.e., a street) or polygon (i.e., a region).
LOCATION_TYPE_RANGE  = "RANGE_INTERPOLATED"
Returned result is between two precise points (usually on a road).
LOCATION_TYPE_ROOFTOP  = "ROOFTOP"
Returned result is a precise street address.
STATUS_INVALID_REQUEST  = "INVALID_REQUEST"
Invalid request, usually because of missing parameter that's required.
STATUS_NO_RESULTS  = "ZERO_RESULTS"
Geocode was successful, but returned no results.
STATUS_OVER_LIMIT  = "OVER_QUERY_LIMIT"
Over limit of 2,500 (100,000 if premier) requests per day.
STATUS_REQUEST_DENIED  = "REQUEST_DENIED"
Request denied, usually because of missing sensor parameter.
STATUS_SUCCESS  = "OK"
No errors occurred, the address was successfully parsed and at least one geocode was returned.
STATUS_UNKNOWN_ERROR  = "UNKNOWN_ERROR"
Unnown server error. May succeed if tried again.
TYPE_ADMIN_AREA_1  = "administrative_area_level_1"
A first-order civil entity below country (states within the US).
TYPE_ADMIN_AREA_2  = "administrative_area_level_2"
A second-order civil entity below country (counties within the US).
TYPE_ADMIN_AREA_3  = "administrative_area_level_3"
A third-order civil entity below country.
TYPE_ADMIN_AREA_4  = "administrative_area_level_4"
A fourth-order civil entity below country.
TYPE_ADMIN_AREA_5  = "administrative_area_level_5"
A fifth-order civil entity below country.
TYPE_AIRPORT  = "airport"
An airport.
TYPE_BUS_STATION  = "bus_station"
A bus stop.
TYPE_COLLOQUIAL_AREA  = "colloquial_area"
A commonly-used alternative name for the entity.
TYPE_COUNTRY  = "country"
A national political entity (country). The highest order type returned.
TYPE_ESTABLISHMENT  = "establishment"
A place that has not yet been categorized.
TYPE_FLOOR  = "floor"
A floor of a building address.
TYPE_INTERSECTION  = "intersection"
A major intersection, usually of two major roads.
TYPE_LOCALITY  = "locality"
An incorporated city or town.
TYPE_NATURAL_FEATURE  = "natural_feature"
A prominent natural feature.
TYPE_NEIGHBORHOOD  = "neighborhood"
A named neighborhood.
TYPE_PARK  = "park"
A named park.
TYPE_PARKING  = "parking"
A parking lot or parking structure.
TYPE_POINT_OF_INTEREST  = "point_of_interest"
A named point of interest that doesn't fit within another category.
TYPE_POLITICAL  = "political"
A political entity, usually of some civil administration.
TYPE_POST_BOX  = "post_box"
A specific postal box.
TYPE_POSTAL_CODE  = "postal_code"
A postal code as used to address mail within the country.
TYPE_POSTAL_TOWN  = "postal_town"
A grouping of geographic areas used for mailing addresses in some countries.
TYPE_PREMISE  = "premise"
A named location, usually a building or collection of buildings.
TYPE_ROOM  = "room"
A room of a building address.
TYPE_ROUTE  = "route"
A named route (such as "US 101").
TYPE_STREET_ADDRESS  = "street_address"
A precise street address.
TYPE_STREET_NUMBER  = "street_number"
A precise street number.
TYPE_SUB_LOCALITY  = "sublocality"
A first-order civil entity below a locality.
TYPE_SUB_PREMISE  = "subpremise"
A first-order entity below a named location, usually a single building within a collection of building with a common name.
TYPE_TRAIN_STATION  = "train_station"
A train stop.
TYPE_TRANSIT_STATION  = "transit_station"
A public transit stop.
TYPE_WARD  = "ward"
A specific type of Japanese locality.
URL_DOMAIN  = "maps.googleapis.com"
Domain portion of the Google Geocoding API URL.
URL_HTTP  = "http://maps.googleapis.com/maps/api/geocode/"
HTTP URL of the Google Geocoding API.
URL_HTTPS  = "https://maps.googleapis.com/maps/api/geocode/"
HTTPS URL of the Google Geocoding API.
URL_PATH  = "/maps/api/geocode/"
Path portion of the Google Geocoding API URL.
__construct()  : GoogleMapsGeocoder
Constructor. The request is not executed until `geocode()` is called.
boundingBox()  : array<string|int, mixed>
Computes a four point bounding box around the specified location. This can then be used to find all locations within an X-mile range of a central location. A bounding box is much easier and faster to compute than a bounding radius.
geocode()  : string|array<string|int, mixed>|SimpleXMLElement
Execute the geocoding request. The return type is based on the requested format: associative array if JSON, SimpleXMLElement object if XML.
getAddress()  : string
Get the address to geocode.
getApiKey()  : string
Get the API key to authenticate with.
getBounds()  : string|false
Get the bounding box coordinates within which to bias geocode results in comma-separated, pipe-delimited format.
getBoundsNortheast()  : string|false
Get the northeast coordinates of the bounding box within which to bias geocode results in comma-separated format.
getBoundsNortheastLatitude()  : float|string
Get the northeast latitude of the bounding box within which to bias geocode results.
getBoundsNortheastLongitude()  : float|string
Get the northeast longitude of the bounding box within which to bias geocode results.
getBoundsSouthwest()  : string|false
Get the southwest coordinates of the bounding box within which to bias geocode results in comma-separated format.
getBoundsSouthwestLatitude()  : float|string
Get the southwest latitude of the bounding box within which to bias geocode results.
getBoundsSouthwestLongitude()  : float|string
Get the southwest longitude of the bounding box within which to bias geocode results.
getClientId()  : string
Get the client ID for Business clients.
getFormat()  : string
Get the response format.
getLanguage()  : string
Get the language code in which to return results.
getLatitude()  : float|string
Get the latitude to reverse geocode to the closest address.
getLatitudeLongitude()  : string|false
Get the latitude/longitude to reverse geocode to the closest address in comma-separated format.
getLocationType()  : array<string|int, mixed>
Get the location type(s) to restrict results to.
getLocationTypeFormatted()  : string
Get the location type(s) to restrict results to separated by a pipe (|).
getLongitude()  : float|string
Get the longitude to reverse geocode to the closest address.
getRegion()  : string
Get the two-character, top-level domain (ccTLD) within which to bias geocode results.
getResultType()  : array<string|int, mixed>
Get the address type(s) to restrict results to.
getResultTypeFormatted()  : string
Get the address type(s) to restrict results to separated by a pipe (|).
getSensor()  : string
Get whether the request is from a device with a location sensor.
getSigningKey()  : string
Get the cryptographic signing key for Business clients.
isBusinessClient()  : bool
Whether the request is for a Business client.
isFormatJson()  : bool
Whether the response format is JSON.
isFormatXml()  : bool
Whether the response format is XML.
setAddress()  : GoogleMapsGeocoder
Set the address to geocode.
setApiKey()  : GoogleMapsGeocoder
Set the API key to authenticate with.
setBounds()  : GoogleMapsGeocoder
Set the bounding box coordinates within which to bias geocode results.
setBoundsNortheast()  : GoogleMapsGeocoder
Set the northeast coordinates of the bounding box within which to bias geocode results.
setBoundsSouthwest()  : GoogleMapsGeocoder
Set the southwest coordinates of the bounding box within which to bias geocode results.
setClientId()  : GoogleMapsGeocoder
Set the client ID for Business clients.
setFormat()  : GoogleMapsGeocoder
Set the response format.
setLanguage()  : GoogleMapsGeocoder
Set the language code in which to return results.
setLatitude()  : GoogleMapsGeocoder
Set the latitude to reverse geocode to the closest address.
setLatitudeLongitude()  : GoogleMapsGeocoder
Set the latitude/longitude to reverse geocode to the closest address.
setLocationType()  : GoogleMapsGeocoder
Set the location type(s) to restrict results to.
setLongitude()  : GoogleMapsGeocoder
Set the longitude to reverse geocode to the closest address.
setRegion()  : GoogleMapsGeocoder
Set the two-character, top-level domain (ccTLD) within which to bias geocode results.
setResultType()  : GoogleMapsGeocoder
Set the address type(s) to restrict results to.
setSensor()  : GoogleMapsGeocoder
Set whether the request is from a device with a location sensor.
setSigningKey()  : GoogleMapsGeocoder
Set the cryptographic signing key for Business clients.

Constants

EQUATOR_LAT_DEGREE_IN_MILES

Helps calculate a more realistic bounding box by taking into account the curvature of the earth's surface.

public mixed EQUATOR_LAT_DEGREE_IN_MILES = 69.172
Tags

LOCATION_TYPE_APPROXIMATE

Returned result is approximate.

public mixed LOCATION_TYPE_APPROXIMATE = "APPROXIMATE"
Tags

LOCATION_TYPE_CENTER

Returned result is the geometric center of a polyline (i.e., a street) or polygon (i.e., a region).

public mixed LOCATION_TYPE_CENTER = "GEOMETRIC_CENTER"
Tags

LOCATION_TYPE_RANGE

Returned result is between two precise points (usually on a road).

public mixed LOCATION_TYPE_RANGE = "RANGE_INTERPOLATED"
Tags

LOCATION_TYPE_ROOFTOP

Returned result is a precise street address.

public mixed LOCATION_TYPE_ROOFTOP = "ROOFTOP"
Tags

STATUS_INVALID_REQUEST

Invalid request, usually because of missing parameter that's required.

public mixed STATUS_INVALID_REQUEST = "INVALID_REQUEST"
Tags

STATUS_NO_RESULTS

Geocode was successful, but returned no results.

public mixed STATUS_NO_RESULTS = "ZERO_RESULTS"
Tags

STATUS_OVER_LIMIT

Over limit of 2,500 (100,000 if premier) requests per day.

public mixed STATUS_OVER_LIMIT = "OVER_QUERY_LIMIT"
Tags

STATUS_REQUEST_DENIED

Request denied, usually because of missing sensor parameter.

public mixed STATUS_REQUEST_DENIED = "REQUEST_DENIED"
Tags

STATUS_SUCCESS

No errors occurred, the address was successfully parsed and at least one geocode was returned.

public mixed STATUS_SUCCESS = "OK"
Tags

STATUS_UNKNOWN_ERROR

Unnown server error. May succeed if tried again.

public mixed STATUS_UNKNOWN_ERROR = "UNKNOWN_ERROR"
Tags

TYPE_ADMIN_AREA_1

A first-order civil entity below country (states within the US).

public mixed TYPE_ADMIN_AREA_1 = "administrative_area_level_1"
Tags

TYPE_ADMIN_AREA_2

A second-order civil entity below country (counties within the US).

public mixed TYPE_ADMIN_AREA_2 = "administrative_area_level_2"
Tags

TYPE_ADMIN_AREA_3

A third-order civil entity below country.

public mixed TYPE_ADMIN_AREA_3 = "administrative_area_level_3"
Tags

TYPE_ADMIN_AREA_4

A fourth-order civil entity below country.

public mixed TYPE_ADMIN_AREA_4 = "administrative_area_level_4"
Tags

TYPE_ADMIN_AREA_5

A fifth-order civil entity below country.

public mixed TYPE_ADMIN_AREA_5 = "administrative_area_level_5"
Tags

TYPE_BUS_STATION

A bus stop.

public mixed TYPE_BUS_STATION = "bus_station"
Tags

TYPE_COLLOQUIAL_AREA

A commonly-used alternative name for the entity.

public mixed TYPE_COLLOQUIAL_AREA = "colloquial_area"
Tags

TYPE_COUNTRY

A national political entity (country). The highest order type returned.

public mixed TYPE_COUNTRY = "country"
Tags

TYPE_ESTABLISHMENT

A place that has not yet been categorized.

public mixed TYPE_ESTABLISHMENT = "establishment"
Tags

TYPE_FLOOR

A floor of a building address.

public mixed TYPE_FLOOR = "floor"
Tags

TYPE_INTERSECTION

A major intersection, usually of two major roads.

public mixed TYPE_INTERSECTION = "intersection"
Tags

TYPE_LOCALITY

An incorporated city or town.

public mixed TYPE_LOCALITY = "locality"
Tags

TYPE_NATURAL_FEATURE

A prominent natural feature.

public mixed TYPE_NATURAL_FEATURE = "natural_feature"
Tags

TYPE_NEIGHBORHOOD

A named neighborhood.

public mixed TYPE_NEIGHBORHOOD = "neighborhood"
Tags

TYPE_PARKING

A parking lot or parking structure.

public mixed TYPE_PARKING = "parking"
Tags

TYPE_POINT_OF_INTEREST

A named point of interest that doesn't fit within another category.

public mixed TYPE_POINT_OF_INTEREST = "point_of_interest"
Tags

TYPE_POLITICAL

A political entity, usually of some civil administration.

public mixed TYPE_POLITICAL = "political"
Tags

TYPE_POST_BOX

A specific postal box.

public mixed TYPE_POST_BOX = "post_box"
Tags

TYPE_POSTAL_CODE

A postal code as used to address mail within the country.

public mixed TYPE_POSTAL_CODE = "postal_code"
Tags

TYPE_POSTAL_TOWN

A grouping of geographic areas used for mailing addresses in some countries.

public mixed TYPE_POSTAL_TOWN = "postal_town"
Tags

TYPE_PREMISE

A named location, usually a building or collection of buildings.

public mixed TYPE_PREMISE = "premise"
Tags

TYPE_ROUTE

A named route (such as "US 101").

public mixed TYPE_ROUTE = "route"
Tags

TYPE_STREET_ADDRESS

A precise street address.

public mixed TYPE_STREET_ADDRESS = "street_address"
Tags

TYPE_STREET_NUMBER

A precise street number.

public mixed TYPE_STREET_NUMBER = "street_number"
Tags

TYPE_SUB_LOCALITY

A first-order civil entity below a locality.

public mixed TYPE_SUB_LOCALITY = "sublocality"
Tags

TYPE_SUB_PREMISE

A first-order entity below a named location, usually a single building within a collection of building with a common name.

public mixed TYPE_SUB_PREMISE = "subpremise"
Tags

TYPE_TRAIN_STATION

A train stop.

public mixed TYPE_TRAIN_STATION = "train_station"
Tags

TYPE_TRANSIT_STATION

A public transit stop.

public mixed TYPE_TRANSIT_STATION = "transit_station"
Tags

TYPE_WARD

A specific type of Japanese locality.

public mixed TYPE_WARD = "ward"
Tags

URL_DOMAIN

Domain portion of the Google Geocoding API URL.

public mixed URL_DOMAIN = "maps.googleapis.com"
Tags

URL_HTTP

HTTP URL of the Google Geocoding API.

public mixed URL_HTTP = "http://maps.googleapis.com/maps/api/geocode/"
Tags

URL_HTTPS

HTTPS URL of the Google Geocoding API.

public mixed URL_HTTPS = "https://maps.googleapis.com/maps/api/geocode/"
Tags

URL_PATH

Path portion of the Google Geocoding API URL.

public mixed URL_PATH = "/maps/api/geocode/"
Tags

Methods

__construct()

Constructor. The request is not executed until `geocode()` is called.

public __construct([string $address = null ][, string $format = self::FORMAT_JSON ][, bool|string $sensor = false ]) : GoogleMapsGeocoder
Parameters
$address : string = null

optional address to geocode

$format : string = self::FORMAT_JSON

optional response format (JSON default)

$sensor : bool|string = false

deprecated as of v2.3.0

Tags
Return values
GoogleMapsGeocoder

boundingBox()

Computes a four point bounding box around the specified location. This can then be used to find all locations within an X-mile range of a central location. A bounding box is much easier and faster to compute than a bounding radius.

public static boundingBox(float|string $latitude, float|string $longitude, int|float|string $mileRange) : array<string|int, mixed>

The returned array contains two keys: 'lat' and 'lon'. Each of these contains another array with two keys: 'max' and 'min'. Four points are returned in total.

Parameters
$latitude : float|string

to draw the bounding box around

$longitude : float|string

to draw the bounding box around

$mileRange : int|float|string

mile range around point

Tags
Return values
array<string|int, mixed>

'lat' and 'lon' 'min' and 'max' points

geocode()

Execute the geocoding request. The return type is based on the requested format: associative array if JSON, SimpleXMLElement object if XML.

public geocode([bool $https = false ][, bool $raw = false ][, resource $context = null ]) : string|array<string|int, mixed>|SimpleXMLElement
Parameters
$https : bool = false

whether to make the request over HTTPS

$raw : bool = false

whether to return the raw (string) response

$context : resource = null

stream context from stream_context_create()

Tags
link
https://developers.google.com/maps/documentation/geocoding/intro#GeocodingResponses
Return values
string|array<string|int, mixed>|SimpleXMLElement

response in requested format

isBusinessClient()

Whether the request is for a Business client.

public isBusinessClient() : bool
Tags
Return values
bool

whether the request is for a Business client

setBounds()

Set the bounding box coordinates within which to bias geocode results.

public setBounds(float|string $southwestLatitude, float|string $southwestLongitude, float|string $northeastLatitude, float|string $northeastLongitude) : GoogleMapsGeocoder
Parameters
$southwestLatitude : float|string

southwest latitude boundary

$southwestLongitude : float|string

southwest longitude boundary

$northeastLatitude : float|string

northeast latitude boundary

$northeastLongitude : float|string

northeast longitude boundary

Tags
link
https://developers.google.com/maps/documentation/geocoding/intro#Viewports
Return values
GoogleMapsGeocoder

        

Search results