GithubHelp home page GithubHelp logo

m-naw / geolocation-bundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 1001pharmacies/geolocation-bundle

0.0 0.0 0.0 197 KB

Provides an abstraction layer for geocoding services.

License: MIT License

PHP 100.00%

geolocation-bundle's Introduction

GeoLocation Bundle

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

geolocation-bundle's People

Contributors

aya avatar crazyball avatar gbprod avatar gcalmels avatar kmonmousseau avatar m-naw avatar methylbro avatar yemm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.