PHP code example of 1001pharmacies / geolocation-bundle

1. Go to this page and download the library: Download 1001pharmacies/geolocation-bundle 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/ */

    

1001pharmacies / geolocation-bundle example snippets


$address = $container
    ->get('meup_geo_location.address_factory')
    ->create()
    ->setFullAddress('360 rue du thor, 34000 Montpellier')
;

$coordinates = $container
    ->get('meup_geo_location.locator')
    ->locate($address)
;

printf(
    "%s,%s\n",
    $coordinates->getLatitude(),
    $coordinates->getLongitude()
);
// output : 43.6190815,3.9162419

$coordinates = $container
    ->get('meup_geo_location.coordinates_factory')
    ->create()
    ->setLatitude(43.6190815)
    ->setLongitude(3.9162419)
;

$address = $container
    ->get('meup_geo_location.locator')
    ->locate($coordinates)
;

print $address->getFullAddress();
// output : 640 Rue du Mas de Verchant, 34000 Montpellier

$factory = $container
    ->get('meup_geo_location.coordinates_factory')
;

$paris = $factory
    ->create()
    ->setLatitude(48.856667)
    ->setLongitude(2.350987)
;
$lyon = $factory
    ->create()
    ->setLatitude(45.767299)
    ->setLongitude(4.834329)
;

$distance_paris_lyon = $container
    ->get('meup_geo_location.distance_calculator')
    ->getDistance($paris, $lyon)
;

printf('%d km', $distance_paris_lyon); # 391.613 km

$bundles = array(
    // ...
    new Meup\Bundle\GeoLocationBundle\MeupGeoLocationBundle(),
);