예제 #1
0
 /**
  * Get more detailed geocode from OSM
  */
 function geocode()
 {
     $geocode = $this->geocodeString();
     // Do not geocode twice
     $geocoded = $this->geocodeKey();
     if ($this->geocoded == $geocoded) {
         return true;
     } else {
         $geocoder = new \Geocoder\Geocoder();
         $adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
         $geocoder->registerProviders(array(new \Geocoder\Provider\OpenStreetMapProvider($adapter)));
         try {
             $geotools = new \League\Geotools\Geotools();
             $cache = new \League\Geotools\Cache\MongoDB();
             $results = $geotools->batch($geocoder)->setCache($cache)->geocode([$geocode])->parallel();
         } catch (Exception $ex) {
             return false;
         }
         if (count($results) > 0) {
             if ($results[0]->getExceptionMessage()) {
                 return false;
             } else {
                 $this->lat = $results[0]->getLatitude();
                 $this->lng = $results[0]->getLongitude();
                 $this->geosource = 'OSM';
                 $this->geocoded = $geocoded;
                 return true;
             }
         } else {
             return false;
         }
     }
 }
예제 #2
0
 public function createService(ServiceLocatorInterface $createService)
 {
     $locale = 'en';
     $geocoder = new \Geocoder\Geocoder();
     $adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
     $geocoder->registerProviders(array(new \Geocoder\Provider\NominatimProvider($adapter, 'http://nominatim.openstreetmap.org', $locale)));
     return $geocoder;
 }
예제 #3
0
 public function __construct()
 {
     $app = $this;
     // -- global generic parameters ---------------------------------------
     $this['app.debug'] = false;
     $this['app.charset'] = 'UTF-8';
     $this['app.name'] = 'shakethenations';
     $this['app.signature'] = 'Shake The Nations!';
     $this['app.feed'] = ' http://www.emsc-csem.org/service/rss/rss.php?typ=emsc&min_lat=10&min_long=-30&max_long=65';
     // -- global directories location -------------------------------------
     $this['app.dir.base'] = realpath(__DIR__ . '/../../../');
     $this['app.dir.cache'] = $this['app.dir.base'] . '/app/Cache';
     $this['app.dir.doc'] = $this['app.dir.base'] . '/doc';
     $this['app.dir.resources'] = $this['app.dir.base'] . '/app/Resources';
     $this['app.dir.translations'] = $this['app.dir.resources'] . '/Translations';
     // -- console ---------------------------------------------------------
     $this['console.input'] = null;
     $this['console.output'] = null;
     $this['console.dialog'] = null;
     // -- timer -----------------------------------------------------------
     $this['app.timer.start'] = 0.0;
     $this['app.timer.finish'] = 0.0;
     // -- event dispatcher ------------------------------------------------
     $this['dispatcher'] = $this->share(function () {
         return new EventDispatcher();
     });
     // -- finder ----------------------------------------------------------
     $this['finder'] = function () {
         return new Finder();
     };
     // -- filesystem ------------------------------------------------------
     $this['filesystem'] = $this->share(function ($app) {
         return new Filesystem();
     });
     // -- configurator ----------------------------------------------------
     $this['configurator'] = $this->share(function ($app) {
         return new Configurator($app);
     });
     $this['parser'] = $this->share(function ($app) {
         return new Parser($app);
     });
     // -- slugger ---------------------------------------------------------
     $this['slugger'] = $app->share(function () use($app) {
         return new Slugger($app);
     });
     // -- geocoder ------------------------------------------------
     $this['geocoder'] = $this->share(function () {
         $geocoder = new \Geocoder\Geocoder();
         $buzz = new \Buzz\Browser(new \Buzz\Client\Curl());
         $adapter = new \Geocoder\HttpAdapter\BuzzHttpAdapter($buzz);
         $geocoder->registerProviders(array(new \Geocoder\Provider\GoogleMapsProvider($adapter)));
         return $geocoder;
     });
     // -- feeder ------------------------------------------------
     $this['feeder.default'] = '\\ShakeTheNations\\Feeders\\EMSCFeeder';
     $this['feeder'] = function ($this) use($app) {
         $class = new \ReflectionClass($this['feeder.default']);
         $instance = $class->newInstanceArgs(array($app));
         return $instance;
     };
 }