public function setAddressAttribute($value) { // // censor address // $censor = new CensorWords; // $badwords = $censor->setDictionary(array('es','en-us', 'en-uk')); // $caddress = $censor->censorString($value); // $address = $caddress['clean']; // search coordinates with the provided address $Geocoder = new \GoogleMapsGeocoder(); // $Geocoder->setAddress($address); $Geocoder->setAddress($value); $response = $Geocoder->geocode(); // defaults when the coordinates aren't found // $this->attributes['address'] = $address; $this->attributes['address'] = $value; $this->attributes['lat'] = '-34.6036844'; $this->attributes['long'] = '-58.381559100000004'; // success, we have coordinates! if ($response['status'] == 'OK') { $info = array('address' => $response['results'][0]['formatted_address'], 'lat' => $response['results'][0]['geometry']['location']['lat'], 'long' => $response['results'][0]['geometry']['location']['lng']); $this->attributes['address'] = $info['address']; $this->attributes['lat'] = $info['lat']; $this->attributes['long'] = $info['long']; } }
public function validate($value, Constraint $constraint) { // On créé un objet GoogleMapsGeocoder prenant en paramètre l'adresse du lieu $adresse $Geocoder = new \GoogleMapsGeocoder(); $Geocoder->setAddress($value); // On test la valeur $reponse = $Geocoder->geocode(); if ($reponse['status'] != "OK" && !is_null($value)) { $this->context->buildViolation($constraint->message)->addViolation(); } }