Download the PHP package biscolab/google-maps-php-sdk without Composer
On this page you can find all versions of the php package biscolab/google-maps-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package google-maps-php-sdk
Google Maps PHP SDK
Google Maps PHP (unofficial library). This provide simple functions to work with Google Maps APIs. You can find further informations in Google Maps Platform Documentation
Google Maps provide many services, actually at this moment this package implements only Geocoding service but others will be available soon.
Reference & Documentation
Go to complete reference or read documentation
Google Maps Services
Ready
- Geocoding :ballot_box_with_check:
- Elevation :ballot_box_with_check:
- Places :ballot_box_with_check:
- Time Zone :ballot_box_with_check:
ASAP
- Directions (soon)
- Distance Matrix (soon)
- Road (soon)
Not scheduled
- Geolocation (not scheduled)
Installation
You can install the package via composer:
Examples
Watch the examples
License
Documentation
This provide simple functions to work with Google Maps APIs. You can find further informations in Google Maps Platform Documentation
Reference
You can find complete API references
Google Maps Services
Ready
- Geocoding
- Elevation (Positional and Sampled Path Requests)
- Places (Search and Details)
- Time Zone
ASAP
- Directions (soon)
- Distance Matrix (soon)
- Road (soon)
Not scheduled
- Geolocation (not scheduled)
System requirements
PHP 7.1 or greater
Composer
Install the package via composer:
Notice! The package is not yet stable, you may find trouble with your minimum stability settings. Further documentation coming asap.
Google Maps is a service supplied by Google and first of all you must register your app project on the Google Cloud Platform Console and get a Google API key which you can add to your app or website (source: official Google Maps documentation).
- Read the Pricing table
- Create your project by clicking on "Get started"
- Create project credentials
- Enable services (Geocoding API, Elevation API, etc...)
Google Console
Geocoding API
The Geocoding API is a service that provides geocoding and reverse geocoding of addresses.
Official Google Geocoding documentation
Initialize Geocoding Object
First of all replace YOUR_API_KEY
with your actual API key.
Get results
You have 3 different ways to retrieve data of your place!
Go to complete SDK reference
Geocoding (Latitude/Longitude Lookup) by address as string
getByAddress
accept following arguments:
Name | Required | Type | Description |
---|---|---|---|
address | yes | string |
The street address or plus code that you want to geocode |
region | no | string |
The region code, specified as a ccTLD ("top-level domain") two-character value. More info here |
Change response language using setLanguage
method
You can find the list of supported languages here: https://developers.google.com/maps/faq#languagesupport
Reverse Geocoding (Address Lookup) by Location/LatLng object
getByLatLng
(getReverse
alias is deprecated) accept a LatLng
object which represents the location of the place.
Change response language using setLanguage
method
You can find the list of supported languages here: https://developers.google.com/maps/faq#languagesupport
By Place ID as string
getByPlaceId
accept as parameter the address the place ID.
Use results
Results is/are a Biscolab\GoogleMaps\Http\GeocodingResultsCollection
object.
First thing you should know how many results there are in your GeocodingResultsCollection
using count
method.
To retrieve the first result you can use the first
method:
$first_result
is an instance of GeocodingResult
class and has the following methods:
Method name | Return Type |
---|---|
getAddressComponents() |
Address |
getFormattedAddress() |
string |
getGeometry() |
Geometry |
getPlaceId() |
string |
getTypes() |
array |
Elevation API
The Elevation API provides elevation data for all locations on the surface of the earth, including depth locations on the ocean floor (which return negative values).
There are two types of request:
- Positional Requests
- Sampled Path Requests
At the moment this package support only Positional Requests but I'm working on Sampled Path Requests and it will be available soon.
Official Google Elevation documentation
Initialize Elevation Object
First of all replace YOUR_API_KEY
with your actual API key.
Get results (Positional Requests)
First of all you have to prepare the locations
variable, it can be a single Location
object, an array of Location
objects or a polyline string.
Single Location object
Create a Location object using latitude and longitude.
Array of Location objects
Using multiple Location objects inside an array
Polyline encoded string
Encode a location using the Encoded Polyline Algorithm Format
Make API call
Get results (Sampled Path Requests)
First of all you have to prepare the path
variable, it can be an array of Location
objects or a polyline string.
Array of Location objects
Using multiple Location objects inside an array
Polyline encoded string
Encode a location using the Encoded Polyline Algorithm Format
Make API call
Use results
Results is/are a Biscolab\GoogleMaps\Http\ElevationResultsCollection
object.
First thing you should know how many results there are in your ElevationResultsCollection
using count
method.
To retrieve the first result you can use the first
method:
$first_result
is an instance of ElevationResult
class and has the following methods:
Method name | Return Type |
---|---|
getLocation() |
Location |
getElevation() |
float |
getResolution() |
float |
Places API
The Places API allows you to query for place information on a variety of categories, such as: establishments, prominent points of interest, geographic locations, and more. You can search for places either by proximity or a text string (credits: Official Documentation website.
There are 3 types of request:
- Find Place requests
- Nearby Search requests
- Text Search requests
Official Google Place documentation
Initialize Places Object
First of all replace YOUR_API_KEY
with your actual API key.
Find Places requests
This function takes a text input (name, address or phone number) and returns a place.
Using name or address
Search place using the "name" or "address".
findPlaceByText
method accepts 3 arguments
Name | Type | Description | Default |
---|---|---|---|
$query |
string |
The address (or the name) specifying which place to search for | Required |
$params |
array |
The list of search params to add to API request | [] |
$fields |
array |
The fields specifying the types of place data to return | [] |
Find further details about request fields (required, types, etc...) here: https://developers.google.com/places/web-service/search#FindPlaceRequests
Using phone number
Search place using the "phone number".
findPlaceByPhoneNumber
method accepts 3 arguments
Name | Type | Description | Default |
---|---|---|---|
$number |
string |
The phone number specifying which place to search for | Required |
$params |
array |
The list of search params to add to API request | [] |
$fields |
array |
The fields specifying the types of place data to return | [] |
Find further details about request fields (required, types, etc...) here: https://developers.google.com/places/web-service/search#FindPlaceRequests
Nearby Search requests
This function looks for places within a specified area.
Using location & radius
findNearbyPlaceByRadius
method accepts 3 arguments
Name | Type | Description | Default |
---|---|---|---|
$location |
Location |
must be instance of Biscolab\GoogleMaps\Object\Location class |
Required |
$radius |
int |
defines the distance in meters. Maximum allowed value is 50000. | Required |
$params |
array |
additional parameters to add to API call | [] |
Rank by distance
findNearbyPlaceByDistance
method accepts 2 arguments
Name | Type | Description | Default |
---|---|---|---|
$location |
Location |
must be instance of Biscolab\GoogleMaps\Object\Location class |
Required |
$params |
array |
additional parameters to add to API call. You MUST set at least one of following values: keyword , name , type |
[] |
Find further details about request fields (required, types, etc...) here: https://developers.google.com/places/web-service/search#PlaceSearchRequests
Text Search request
This service returns information about a set of places based on a string.
Search by query
textSearch
method accepts 2 arguments
Name | Type | Description | Default |
---|---|---|---|
$query |
string |
The text string on which to search, for example: "restaurant" or "123 Main Street". | Required |
$params |
array |
additional parameters to add to API call | [] |
Find further details about request fields (required, types, etc...) here: https://developers.google.com/places/web-service/search#TextSearchRequests
Place's Details
details
method accepts 2 arguments
Name | Type | Description | Default |
---|---|---|---|
$place_id |
string |
A textual identifier that uniquely identifies a place, returned from a Place Search. | Required |
$params |
array |
additional parameters to add to API call | [] |
Find further details about request fields (required, types, etc...) here: https://developers.google.com/places/web-service/details#PlaceDetailsRequests
Use results
Results is/are a Biscolab\GoogleMaps\Http\PlaceResultsCollection
object.
Current page
First thing you should know how many results there are in your PlaceResultsCollection
using count
method.
To retrieve the first result you can use the first
method:
$first_result
is an instance of PlaceResult
class and has the following methods:
Method name | Return Type |
---|---|
getPhotos() |
PhotoCollection |
getGeometry() |
Geometry |
getFormattedAddress() |
string |
getName() |
string |
getIcon() |
string |
getId() |
string |
getPlaceId() |
string |
getReference() |
string |
getVicinity() |
string |
getTypes() |
array |
getOpeningHours() |
array |
getPriceLevel() |
int |
getRating() |
float |
getPermanentlyClose() |
bool |
getPlusCode() |
array |
Next result page
Results can be paginated. How do you know id a result has more pages?
`
Time Zone API
The Time Zone API provides time offset data for locations on the surface of the earth
Official Google TimeZone documentation
Initialize TimeZone Object
First of all replace YOUR_API_KEY
with your actual API key.
Get result
Go to complete SDK reference
By location and timestamp
get
accepts 3 arguments
Name | Requested | Type | Description | |
---|---|---|---|---|
$location |
Yes | Biscolab\GoogleMaps\Object\Location | Represents the location to look up | |
$timestamp |
Yes | integer | The Time Zone API uses the $timestamp to determine whether or not Daylight Savings should be applied, based on the time zone of the $location |
|
$language |
No | string | The language in which to return results |
Use result
Result is an instance of Biscolab\GoogleMaps\Http\Result\TimeZoneResult
class and has the following methods:
Method name | Return Type |
---|---|
getDdstOffset() |
int |
getRawOffset() |
int |
getTimeZoneId() |
string |
getTimeZoneName() |
string |