1. Go to this page and download the library: Download yidas/google-maps-services library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yidas / google-maps-services example snippets
$gmaps = new \yidas\googleMaps\Client(['key'=>'Your API Key']);
// Geocoding an address
$geocodeResult = $gmaps->geocode('Taipei 101, Taipei City, Taiwan 110');
// Look up an address with reverse geocoding
$reverseGeocodeResult = $gmaps->reverseGeocode([25.0339639, 121.5644722]);
// Request directions via public transit
$directionsResult = $gmaps->directions('National Palace Museum', 'Taipei 101', [
'mode' => "transit",
'departure_time' => time(),
]);
use yidas\googleMaps\Client;
$gmaps = new \yidas\googleMaps\Client(['key'=>'Your API Key']);
$gmaps = new \yidas\googleMaps\Client([
'clientID' => 'Your client ID',
'clientSecret' => 'Your digital signature'
]);
$gmaps = new \yidas\googleMaps\Client(['key'=>'Your API Key', 'language'=>'zh-TW']);
$gmaps->setLanguage('zh-TW');
// ...
// Get elevation by locations parameter
$elevationResult = $gmaps->elevation([25.0339639, 121.5644722]);
$elevationResult = $gmaps->elevation('25.0339639, 121.5644722');
$routes = $gmaps->computeRoutes($originArray, $destinationArray, $fullBodyArray, $fieldMask)
// Get the route data between two places simply
$routes = $gmaps->computeRoutes([
"location" => [
"latLng" => [
"latitude" => 37.419734,
"longitude" => -122.0827784
]
]
],
[
"location" => [
"latLng" => [
"latitude" => 37.41767,
"longitude" => -122.079595
]
]
]);
// Get the full route data between two places with full request data
$routes = $gmaps->computeRoutes([...], [...], ["travelMode": "DRIVE", ...], '*');
// Get the distance matrix data between two places
$distanceMatrixResult = $gmaps->distanceMatrix('National Palace Museum', 'Taipei 101');
// With Imperial units
$distanceMatrixResult = $gmaps->distanceMatrix('National Palace Museum', 'Taipei 101', [
'units' => 'imperial',
]);
// Geocoding an address
$geocodeResult = $gmaps->geocode('Taipei 101, Taipei City, Taiwan 110');
// Look up an address with reverse geocoding
$reverseGeocodeResult = $gmaps->reverseGeocode([25.0339639, 121.5644722]);