PHP code example of biscolab / google-maps-php-sdk
1. Go to this page and download the library: Download biscolab/google-maps-php-sdk 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/ */
biscolab / google-maps-php-sdk example snippets
use Biscolab\GoogleMaps\Api\Geocoding;
use Biscolab\GoogleMaps\Enum\GoogleMapsApiConfigFields;
$geocoding = new Geocoding([
GoogleMapsApiConfigFields::KEY => 'YOUR_API_KEY'
]);
$results = $geocoding->getByAddress('Insert your address here, city, postal code etc...');
// Set Spanish language
$results = $geocoding->setLanguage('es')->getByAddress('Insert your address here, city, postal code etc...');
// Set Spanish language
$results = $geocoding->setLanguage('es')->getByLatLng(new LatLng([
LatLngFields::LAT => $lat,
LatLngFields::LNG => $lng,
]));
// Use the same way for getReverse (alias) method
use Biscolab\GoogleMaps\Api\Elevation;
use Biscolab\GoogleMaps\Enum\GoogleMapsApiConfigFields;
$elevation = new Elevation([
GoogleMapsApiConfigFields::KEY => 'YOUR_API_KEY'
]);
// get results by single Location object
$locations = new Location([
LatLngFields::LAT => 39.73915360,
LatLngFields::LNG => -104.9847034,
]);
// or by multiple Location objects
$locations = [
new Location([
LatLngFields::LAT => 39.73915360,
LatLngFields::LNG => -104.9847034,
]),
// ... more locations
new Location([
LatLngFields::LAT => 50.123,
LatLngFields::LNG => 99.456,
])
];
// or by polyline
$locations = 'enc:gfo}EtohhU';
// make API call
$results = $elevation->getByLocations($locations);
// or by multiple Location objects
$path = [
new Location([
LatLngFields::LAT => 39.73915360,
LatLngFields::LNG => -104.9847034,
]),
// ... more locations
new Location([
LatLngFields::LAT => 50.123,
LatLngFields::LNG => 99.456,
])
];
// or by polyline
$path = 'enc:gfo}EtohhUxD@bAxJmGF';
// make API call
$samples = 5; // must be int > 0
$results = $elevation->getBySampledPath($path, $samples);
$number_of_results = $results->count();
$first_result = $results->first();
use Biscolab\GoogleMaps\Api\Places;
use Biscolab\GoogleMaps\Enum\GoogleMapsApiConfigFields;
$place = new Places([
GoogleMapsApiConfigFields::KEY => 'YOUR_API_KEY'
]);
use Biscolab\GoogleMaps\Fields\GoogleMapsRequestFields;
// get results by place's name or address
$result = $places->findPlaceByText("Museum of Contemporary Art Australia");
use Biscolab\GoogleMaps\Fields\GoogleMapsRequestFields;
// get results by place's phone number
$result = $places->findPlaceByPhoneNumber("+61293744000");
use Biscolab\GoogleMaps\Object\Location;
use Biscolab\GoogleMaps\Fields\GoogleMapsRequestFields;
$location = new Location([
LatLngFields::LAT => -33.8670522,
LatLngFields::LNG => 151.1957362,
]);
$radius = 1000;
$result = $places->findNearbyPlaceByRadius($location, $radius);
use Biscolab\GoogleMaps\Object\Location;
use Biscolab\GoogleMaps\Fields\GoogleMapsRequestFields;
$location = new Location([
LatLngFields::LAT => -33.8670522,
LatLngFields::LNG => 151.1957362,
]);
// You MUST set at least one of following values
$params = [
GoogleMapsRequestFields::KEYWORD => 'a keyword',
GoogleMapsRequestFields::NAME => 'name of the place you are looking for',
// Biscolab\GoogleMaps\Values\PlaceTypeValues enum class
GoogleMapsRequestFields::TYPE => 'Type of the place you are looking for'
];
$result = $places->findNearbyPlaceByDistance($location, $params);
use Biscolab\GoogleMaps\Fields\GoogleMapsRequestFields;
$query = "restaurants in Sydney";
$params = [
...
];
$result = $places->textSearch($query, $params);
// getNextPage method checks if $result has "next page"
$next_page_result = $result->getNextPage();
use Biscolab\GoogleMaps\Api\TimeZone;
use Biscolab\GoogleMaps\Enum\GoogleMapsApiConfigFields;
$timezone = new TimeZone([
GoogleMapsApiConfigFields::KEY => 'YOUR_API_KEY'
]);