From c632278e1477479cae62469055a8dfca96c23239 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 8 Aug 2022 14:21:57 +0700 Subject: [PATCH] project geolocation --- app/Http/Controllers/ProjectController.php | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 507cb74..1855eca 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -28,6 +28,8 @@ use App\Models\ReportActivity; use App\Models\OfficeHours; use DB; +const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; + class ProjectController extends Controller { @@ -245,7 +247,6 @@ class ProjectController extends Controller $d->plannedCost = $d->rencana_biaya; $d->actualCost = $actualCost; $d->lastActivity = $lastActivity ?? "-"; - //$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2; $d->costVariance = $costVariance; $d->costHealth = $d->budget_health; $d->scheduleHealth = $scheduleHealth; @@ -257,6 +258,11 @@ class ProjectController extends Controller ->where('m_proyek.id', $d->id) ->pluck('m_users.name') ->first(); + if($d->area_kerja != ''){ + $d->geolocation = $this->httpReq($d->area_kerja); + } else { + $d->geolocation = ''; + } } $totalPlannedCost = $data->sum('plannedCost'); @@ -365,4 +371,20 @@ class ProjectController extends Controller return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes, 'totalRecord'=>$countData], 200); } + + private function httpReq($search){ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); + + // SSL important + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + //curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + $output = curl_exec($ch); + curl_close($ch); + + return json_decode($output); + } + }