/** * 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; } } }