Fix: correzione geolocalizzazione sede

This commit is contained in:
Beppe 2024-10-31 17:19:02 +01:00
parent 0b1e4d764e
commit c1fe61e464
1 changed files with 9 additions and 9 deletions

View File

@ -120,17 +120,17 @@ class Sede extends Model
$this->lat = $data[0]->lat; $this->lat = $data[0]->lat;
$this->lng = $data[0]->lon; $this->lng = $data[0]->lon;
} elseif (setting('Gestore mappa') == 'Google Maps') { } elseif (setting('Gestore mappa') == 'Google Maps') {
$curl = new CurlHttpAdapter(); $apiKey = setting('Google Maps API key per Tecnici');
$geocoder = new GoogleMaps($curl, 'IT-it', null, true, $google); $url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.$indirizzo.'&key='.$apiKey;
// Ricerca indirizzo $response = file_get_contents($url);
$address = $geocoder->geocode($indirizzo)->first(); $data = json_decode($response, true);
$coordinates = $address->getCoordinates();
// Salvataggio informazioni if ($data['status'] == 'OK') {
$this->gaddress = $data[0]->display_name; $this->lat = $data['results'][0]['geometry']['location']['lat'];
$this->lat = $coordinates->getLatitude(); $this->lng = $data['results'][0]['geometry']['location']['lng'];
$this->lng = $coordinates->getLongitude(); $this->gaddress = $data['results'][0]['formatted_address'];
}
} }
} }
} }