1001pharmacies/geolocation-bundle

Provides an abstraction layer for geocoding services.

Installs: 6 759

Dependents: 0

Suggesters: 0

Security: 0

Stars: 10

Watchers: 15

Forks: 5

Open Issues: 2

Type:symfony-bundle

v1.1.1 2017-11-02 07:10 UTC

This package is not auto-updated.

Last update: 2024-04-19 18:42:43 UTC


README

Build Status Total Downloads Latest Stable Version

Provides an abstraction layer for geocoding services. This bundle can be also used to split geocoding's calculation between a set of external geocoding service.

Supported providers

The following services are included to this bundle :

The the complete documentation to add you own provider.

Example

Spatial coordinates and postal address correspondence

Coordinates by Address

$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

The geolocation-bundle only provides library ands services. But you can easily integrate it in your applications.

Address by Coordinates

$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

Distance calculation

When you found two location's coordinates you can also calculate their distance with the distance calculator.

$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

Installation

Install the package with Composer :

composer require 1001pharmacies/geolocation-bundle

Or update the composer.json file :

"require": {
    "1001pharmacies/geolocation-bundle": "~1.0"
}

Update app/AppKernel.php :

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

Setup your app/config/parameters.yml with your api keys :

parameters:
    # ...
    geo_location_google_api_key:     your_google_api_key
    geo_location_bing_api_key:       your_bing_api_key
    geo_location_nominatim_api_key:  null
    geo_location_mapquest_api_key:   your_mapquest_api_key
    geo_location_yandex_api_key:     null
    geo_location_heredotcom_api_key: your_heredotcom_api_key

See detailed Google and Bing documentation to know how to retrieve api keys.

Customization