mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-17 03:51:06 +01:00
Gestione ricerca coordinate openstreetmap
This commit is contained in:
parent
af2be23336
commit
84ffd4922e
@ -23,7 +23,6 @@ use Modules\Anagrafiche\Anagrafica;
|
|||||||
use Modules\Anagrafiche\Export\CSV;
|
use Modules\Anagrafiche\Export\CSV;
|
||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
$google = setting('Google Maps API key');
|
|
||||||
|
|
||||||
switch (post('op')) {
|
switch (post('op')) {
|
||||||
case 'delete-bulk':
|
case 'delete-bulk':
|
||||||
@ -44,21 +43,26 @@ switch (post('op')) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ricerca-coordinate':
|
case 'ricerca-coordinate':
|
||||||
$curl = new CurlHttpAdapter();
|
|
||||||
$geocoder = new GoogleMaps($curl, null, null, true, $google);
|
|
||||||
|
|
||||||
foreach ($id_records as $id) {
|
foreach ($id_records as $id) {
|
||||||
$anagrafica = Anagrafica::find($id);
|
$anagrafica = Anagrafica::find($id);
|
||||||
if (empty($anagrafica->lat) && empty($anagrafica->lng) && !empty($anagrafica->sedeLegale->citta) && !empty($anagrafica->sedeLegale->cap)) {
|
if (empty($anagrafica->lat) && empty($anagrafica->lng) && !empty($anagrafica->sedeLegale->citta) && !empty($anagrafica->sedeLegale->cap)) {
|
||||||
$indirizzo = $anagrafica->sedeLegale->citta.' '.$anagrafica->sedeLegale->cap;
|
$indirizzo = urlencode($anagrafica->sedeLegale->citta.' '.$anagrafica->sedeLegale->cap);
|
||||||
|
|
||||||
// Ricerca indirizzo
|
// TODO: da riscrivere con Guzzle e spostare su hook
|
||||||
$address = $geocoder->geocode($indirizzo)->first();
|
$ch = curl_init();
|
||||||
$coordinates = $address->getCoordinates();
|
$url = "https://nominatim.openstreetmap.org/search.php?q=".$indirizzo."&format=jsonv2";
|
||||||
|
$user_agent = 'traccar';
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
$data = json_decode(curl_exec($ch));
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
// Salvataggio informazioni
|
// Salvataggio informazioni
|
||||||
$anagrafica->lat = $coordinates->getLatitude();
|
$anagrafica->gaddress = $data[0]->display_name;
|
||||||
$anagrafica->lng = $coordinates->getLongitude();
|
$anagrafica->lat = $data[0]->lat;
|
||||||
|
$anagrafica->lng = $data[0]->lon;
|
||||||
$anagrafica->save();
|
$anagrafica->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +118,7 @@ $operations['export-csv'] = [
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
if (App::debug() && $google) {
|
if (App::debug()) {
|
||||||
$operations['ricerca-coordinate'] = [
|
$operations['ricerca-coordinate'] = [
|
||||||
'text' => '<span><i class="fa fa-map"></i> '.tr('Ricerca coordinate').'</span>',
|
'text' => '<span><i class="fa fa-map"></i> '.tr('Ricerca coordinate').'</span>',
|
||||||
'data' => [
|
'data' => [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user