Unverified Commit 2d310630 authored by Sebastian Castro's avatar Sebastian Castro
Browse files

Fix geocoder

parent ba567c48
......@@ -4,15 +4,21 @@ bazinga_geocoder:
# see https://github.com/geocoder-php/BazingaGeocoderBundle/blob/5.0.0/Resources/doc/index.md#fake-local-ip
fake_ip: 123.123.123.123
providers:
# See https://github.com/geocoder-php/BazingaGeocoderBundle/blob/master/Resources/doc/services.md
google_maps:
locale: fr
locale: '%locale%'
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
options:
# httplug_client: '@httplug.client' # When using HTTPlugBundle
# region: 'Sweden'
api_key: 'AIzaSyBgah9u8A21CdN6O_fN80Op-4zcLJ0EwXk'
# region: null
# use_ssl: true
# api_key:
# mapbox:
# locale: '%locale%'
# factory: Bazinga\GeocoderBundle\ProviderFactory\MapboxFactory
# options:
# api_key: ''
# openstreetmap:
# locale: fr
\ No newline at end of file
# locale: '%locale%'
# factory: Bazinga\GeocoderBundle\ProviderFactory\NominatimFactory
# options:
# root_url: ''
......@@ -63,7 +63,8 @@ class RegistrationFormHandler
if ($user->getLocation()) {
try
{
$geocoded = $this->geocoder->using('google_maps')->geocode($user->getLocation())->first();
$geocoded = $this->geocoder->using('google_maps')->geocode($user->getLocation())
->first()->getCoordinates();
$user->setGeo(new Coordinates($geocoded->getLatitude(), $geocoded->getLongitude()));
}
catch (\Exception $error) { $geocodeError = true; }
......
......@@ -12,6 +12,7 @@ use Symfony\Component\Form\FormError;
use App\Document\Coordinates;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Doctrine\ODM\MongoDB\DocumentManager;
use Geocoder\ProviderAggregator;
class UserController extends GoGoController
{
......@@ -100,7 +101,8 @@ class UserController extends GoGoController
return $this->redirectToRoute('gogo_user_contributions');
}
public function profileAction(Request $request, SessionInterface $session, DocumentManager $dm)
public function profileAction(Request $request, SessionInterface $session, DocumentManager $dm,
ProviderAggregator $geocoder)
{
$user = $this->getUser();
$current_user = clone $user;
......@@ -121,7 +123,8 @@ class UserController extends GoGoController
if ($user->getLocation()) {
try
{
$geocoded = $this->get('bazinga_geocoder.geocoder')->using('google_maps')->geocode($user->getLocation())->first();
$geocoded = $geocoder->using('google_maps')->geocode($user->getLocation())
->first()->getCoordinates();
$user->setGeo(new Coordinates($geocoded->getLatitude(), $geocoded->getLongitude()));
}
catch (\Exception $error) { $geocodeError = true; }
......
......@@ -139,7 +139,7 @@ class ElementImportOneService
$lat = 0; $lng = 0;
if ($import->getGeocodeIfNecessary())
{
$result = $this->geocoder->geocode($address->getFormatedAddress())->first();
$result = $this->geocoder->geocode($address->getFormatedAddress())->first()->getCoordinates();
$lat = $result->getLatitude();
$lng = $result->getLongitude();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment