PHP code example of langleyfoxall / simple-google-maps

1. Go to this page and download the library: Download langleyfoxall/simple-google-maps 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/ */

    

langleyfoxall / simple-google-maps example snippets


// Standard authentication:
$simpleGoogleMaps = SimpleGoogleMapsFactory::getByKey(getenv('KEY'));

// Enterprise / premium plan authentication:
$simpleGoogleMaps = SimpleGoogleMapsFactory::getByClientNameAndCryptKey(getenv('CLIENT_NAME'), getenv('CRYPT_KEY'));

$latLng = $simpleGoogleMaps->geocode('10 Downing St, Westminster, London SW1A UK');

$latLng = $simpleGoogleMaps->allowPartialMatches()->geocode('test address');

$latitude = $latLng->lat;
$longitude = $latLng->long;

$distance = $fromCoords->distanceTo($toCoords);

$address = $simpleGoogleMaps->reverseGeocode(new LatLong(51.5033635, -0.1276248));

$address1 = "10 Downing St, Westminster, London SW1A UK";
$address2 = "Schott House, Drummond Rd, Stafford ST16 3EL";

$journey = $simpleGoogleMaps->directions($address1, $address2, TravelMode::DRIVING);

foreach($journey as $step) {
    echo $step->duration.' secs  ';
    echo "\t";
    echo $step->distance.' m    ';
    echo "\t";
    echo $step->description;
    echo PHP_EOL;
}

echo 'Totals: '.$journey->duration().' secs, '.$journey->distance().' km';
echo PHP_EOL;