A PHP wrapper for the Google Maps Geocoding API v3.
Methods
Constructor. The request is not executed until `geocode()` is called.
__construct(string $address = null
, string $format = self::FORMAT_JSON
, bool|string $sensor = false
) : \GoogleMapsGeocoder
Parameters
$address
string
optional address to geocode
$format
string
optional response format (JSON default)
$sensor
bool
string
deprecated as of v2.3.0
Returns
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.
boundingBox(float|string $latitude, float|string $longitude, int|float|string $mileRange) : array
Static
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
Returns
array
'lat' and 'lon' 'min' and 'max' points
Execute the geocoding request. The return type is based on the requested
format: associative array if JSON, SimpleXMLElement object if XML.
geocode(bool $https = false
, bool $raw = false
, resource $context = null
) : string | array | \SimpleXMLElement
Parameters
$https
bool
whether to make the request over HTTPS
$raw
bool
whether to return the raw (string) response
$context
resource
stream context from stream_context_create()
Returns
Get the address to geocode.
getAddress() : string
Get the API key to authenticate with.
getApiKey() : string
Get the bounding box coordinates within which to bias geocode results
in comma-separated, pipe-delimited format.
getBounds() : string | false
Returns
string
false
comma-separated, pipe-delimited coordinates, or
false if not set
Get the northeast coordinates of the bounding box within which to bias
geocode results in comma-separated format.
getBoundsNortheast() : string | false
Returns
string
false
comma-separated coordinates, or false if not set
Get the northeast latitude of the bounding box within which to bias
geocode results.
getBoundsNortheastLatitude() : float | string
Returns
float
string
northeast latitude boundary
Get the northeast longitude of the bounding box within which to bias
geocode results.
getBoundsNortheastLongitude() : float | string
Returns
float
string
northeast longitude boundary
Get the southwest coordinates of the bounding box within which to bias
geocode results in comma-separated format.
getBoundsSouthwest() : string | false
Returns
string
false
comma-separated coordinates, or false if not set
Get the southwest latitude of the bounding box within which to bias
geocode results.
getBoundsSouthwestLatitude() : float | string
Returns
float
string
southwest latitude boundary
Get the southwest longitude of the bounding box within which to bias
geocode results.
getBoundsSouthwestLongitude() : float | string
Returns
float
string
southwest longitude boundary
Get the client ID for Business clients.
getClientId() : string
Get the language code in which to return results.
getLanguage() : string
Returns
string
language code
Get the latitude to reverse geocode to the closest address.
getLatitude() : float | string
Returns
float
string
latitude to reverse geocode
Get the latitude/longitude to reverse geocode to the closest address
in comma-separated format.
getLatitudeLongitude() : string | false
Returns
string
false
comma-separated coordinates, or false if not set
Get the location type(s) to restrict results to.
getLocationType() : array
Returns
array
location type(s)
Get the longitude to reverse geocode to the closest address.
getLongitude() : float | string
Returns
float
string
longitude to reverse geocode
Get the two-character, top-level domain (ccTLD) within which to bias
geocode results.
getRegion() : string
Returns
string
two-character, top-level domain (ccTLD)
Get the address type(s) to restrict results to.
getResultType() : array
Returns
array
address type(s)
Get whether the request is from a device with a location sensor.
getSensor() : string
Returns
string
'true' or 'false'
Get the cryptographic signing key for Business clients.
getSigningKey() : string
Returns
string
cryptographic signing key
Whether the request is for a Business client.
isBusinessClient() : bool
Returns
bool
whether the request is for a Business client
Set the address to geocode.
setAddress(string $address) : \GoogleMapsGeocoder
Parameters
$address
string
address to geocode
Returns
Set the bounding box coordinates within which to bias geocode results.
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
Returns
Set the northeast coordinates of the bounding box within which to bias
geocode results.
setBoundsNortheast(float|string $latitude, float|string $longitude) : \GoogleMapsGeocoder
Parameters
$latitude
float
string
northeast latitude boundary
$longitude
float
string
northeast longitude boundary
Returns
Set the southwest coordinates of the bounding box within which to bias
geocode results.
setBoundsSouthwest(float|string $latitude, float|string $longitude) : \GoogleMapsGeocoder
Parameters
$latitude
float
string
southwest latitude boundary
$longitude
float
string
southwest longitude boundary
Returns
Set the client ID for Business clients.
setClientId(string $clientId) : \GoogleMapsGeocoder
Parameters
$clientId
string
client ID
Returns
Set the language code in which to return results.
setLanguage(string $language) : \GoogleMapsGeocoder
Parameters
$language
string
language code
Returns
Set the latitude to reverse geocode to the closest address.
setLatitude(float|string $latitude) : \GoogleMapsGeocoder
Parameters
$latitude
float
string
latitude to reverse geocode
Returns
Set the latitude/longitude to reverse geocode to the closest address.
setLatitudeLongitude(float|string $latitude, float|string $longitude) : \GoogleMapsGeocoder
Parameters
$latitude
float
string
latitude to reverse geocode
$longitude
float
string
longitude to reverse geocode
Returns
Set the location type(s) to restrict results to.
setLocationType(string|array $locationType) : \GoogleMapsGeocoder
Parameters
$locationType
string
array
location type(s)
Returns
Set the longitude to reverse geocode to the closest address.
setLongitude(float|string $longitude) : \GoogleMapsGeocoder
Parameters
$longitude
float
string
longitude to reverse geocode
Returns
Set the two-character, top-level domain (ccTLD) within which to bias
geocode results.
setRegion(string $region) : \GoogleMapsGeocoder
Parameters
$region
string
two-character, top-level domain (ccTLD)
Returns
Set the address type(s) to restrict results to.
setResultType(string|array $resultType) : \GoogleMapsGeocoder
Parameters
$resultType
string
array
address type(s)
Returns
Set whether the request is from a device with a location sensor.
setSensor(bool|string $sensor) : \GoogleMapsGeocoder
Parameters
$sensor
bool
string
boolean or 'true'/'false' string
Returns
Set the cryptographic signing key for Business clients.
setSigningKey(string $signingKey) : \GoogleMapsGeocoder
Parameters
$signingKey
string
cryptographic signing key
Returns
Decode a Base64 string that uses only URL safe characters.
base64DecodeUrlSafe(string $value) : string
Static
Parameters
$value
string
value to decode
Returns
string
decoded value
Encode a string with Base64 using only URL safe characters.
base64EncodeUrlSafe(string $value) : string
Static
Parameters
$value
string
value to encode
Returns
string
encoded value
Generate the signature for a Business client geocode request.
generateSignature(string $pathQueryString) : string
Parameters
$pathQueryString
string
path and query string of the request
Returns
string
Base64 encoded signature that's URL safe
Build the query string with all set parameters of the geocode request.
geocodeQueryString() : string
Returns
string
encoded query string of the geocode request
Build the URL (with query string) of the geocode request.
geocodeUrl(bool $https = false
) : string
Parameters
$https
bool
whether to make the request over HTTPS
Returns
string
URL of the geocode request
Properties
Address to geocode.
$address : string
API key to authenticate with.
$apiKey : string
Northeast latitude of the bounding box within which to bias geocode
results.
$boundsNortheastLatitude : float | string
Northeast longitude of the bounding box within which to bias geocode
results.
$boundsNortheastLongitude : float | string
Southwest latitude of the bounding box within which to bias geocode
results.
$boundsSouthwestLatitude : float | string
Southwest longitude of the bounding box within which to bias geocode
results.
$boundsSouthwestLongitude : float | string
Client ID for Business clients.
$clientId : string
Language code in which to return results.
$language : string
Latitude to reverse geocode to the closest address.
$latitude : float | string
Location type(s) to restrict results to.
$locationType : array
Longitude to reverse geocode to the closest address.
$longitude : float | string
Two-character, top-level domain (ccTLD) within which to bias geocode
results.
$region : string
Address type(s) to restrict results to.
$resultType : array
Whether the request is from a device with a location sensor.
$sensor : string
deprecated |
2.3.0 no longer required by the Google Maps API |
Cryptographic signing key for Business clients.
$signingKey : string
Constants
Helps calculate a more realistic bounding box by taking into account the
curvature of the earth's surface.
EQUATOR_LAT_DEGREE_IN_MILES = 69.172
Returned result is approximate.
LOCATION_TYPE_APPROXIMATE = "APPROXIMATE"
Returned result is the geometric center of a polyline (i.e., a street)
or polygon (i.e., a region).
LOCATION_TYPE_CENTER = "GEOMETRIC_CENTER"
Returned result is between two precise points (usually on a road).
LOCATION_TYPE_RANGE = "RANGE_INTERPOLATED"
Returned result is a precise street address.
LOCATION_TYPE_ROOFTOP = "ROOFTOP"
Invalid request, usually because of missing parameter that's required.
STATUS_INVALID_REQUEST = "INVALID_REQUEST"
Geocode was successful, but returned no results.
STATUS_NO_RESULTS = "ZERO_RESULTS"
Over limit of 2,500 (100,000 if premier) requests per day.
STATUS_OVER_LIMIT = "OVER_QUERY_LIMIT"
Request denied, usually because of missing sensor parameter.
STATUS_REQUEST_DENIED = "REQUEST_DENIED"
No errors occurred, the address was successfully parsed and at least one
geocode was returned.
STATUS_SUCCESS = "OK"
Unnown server error. May succeed if tried again.
STATUS_UNKNOWN_ERROR = "UNKNOWN_ERROR"
A first-order civil entity below country (states within the US).
TYPE_ADMIN_AREA_1 = "administrative_area_level_1"
A second-order civil entity below country (counties within the US).
TYPE_ADMIN_AREA_2 = "administrative_area_level_2"
A third-order civil entity below country.
TYPE_ADMIN_AREA_3 = "administrative_area_level_3"
A fourth-order civil entity below country.
TYPE_ADMIN_AREA_4 = "administrative_area_level_4"
A fifth-order civil entity below country.
TYPE_ADMIN_AREA_5 = "administrative_area_level_5"
An airport.
TYPE_AIRPORT = "airport"
A bus stop.
TYPE_BUS_STATION = "bus_station"
A commonly-used alternative name for the entity.
TYPE_COLLOQUIAL_AREA = "colloquial_area"
A national political entity (country). The highest order type returned.
TYPE_COUNTRY = "country"
A place that has not yet been categorized.
TYPE_ESTABLISHMENT = "establishment"
A floor of a building address.
TYPE_FLOOR = "floor"
A major intersection, usually of two major roads.
TYPE_INTERSECTION = "intersection"
An incorporated city or town.
TYPE_LOCALITY = "locality"
A prominent natural feature.
TYPE_NATURAL_FEATURE = "natural_feature"
A named neighborhood.
TYPE_NEIGHBORHOOD = "neighborhood"
A named park.
TYPE_PARK = "park"
A parking lot or parking structure.
TYPE_PARKING = "parking"
A named point of interest that doesn't fit within another category.
TYPE_POINT_OF_INTEREST = "point_of_interest"
A political entity, usually of some civil administration.
TYPE_POLITICAL = "political"
A postal code as used to address mail within the country.
TYPE_POSTAL_CODE = "postal_code"
A grouping of geographic areas used for mailing addresses in some
countries.
TYPE_POSTAL_TOWN = "postal_town"
A specific postal box.
TYPE_POST_BOX = "post_box"
A named location, usually a building or collection of buildings.
TYPE_PREMISE = "premise"
A room of a building address.
TYPE_ROOM = "room"
A named route (such as "US 101").
TYPE_ROUTE = "route"
A precise street address.
TYPE_STREET_ADDRESS = "street_address"
A precise street number.
TYPE_STREET_NUMBER = "street_number"
A first-order civil entity below a locality.
TYPE_SUB_LOCALITY = "sublocality"
A first-order entity below a named location, usually a single building
within a collection of building with a common name.
TYPE_SUB_PREMISE = "subpremise"
A train stop.
TYPE_TRAIN_STATION = "train_station"
A public transit stop.
TYPE_TRANSIT_STATION = "transit_station"
A specific type of Japanese locality.
TYPE_WARD = "ward"
Domain portion of the Google Geocoding API URL.
URL_DOMAIN = "maps.googleapis.com"
HTTP URL of the Google Geocoding API.
URL_HTTP = "http://maps.googleapis.com/maps/api/geocode/"
HTTPS URL of the Google Geocoding API.
URL_HTTPS = "https://maps.googleapis.com/maps/api/geocode/"
Path portion of the Google Geocoding API URL.
URL_PATH = "/maps/api/geocode/"