Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-j 51
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-j 51
22_23-j 51
Commits
05d5efd2
Commit
05d5efd2
authored
Apr 07, 2023
by
Hasith Yoman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
station list with queue count
parent
2a241981
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
fuel-sliit-bakend-main/app/Http/Controllers/StationController.php
...it-bakend-main/app/Http/Controllers/StationController.php
+30
-0
No files found.
fuel-sliit-bakend-main/app/Http/Controllers/StationController.php
View file @
05d5efd2
...
...
@@ -31,6 +31,34 @@ class StationController extends Controller
}
return
response
()
->
json
([
'respond'
=>
$respond
,
'count'
=>
$queue
]);
}
public
function
getNearestFuelStations
(
Request
$req
)
{
$fuelStations
=
Station
::
join
(
'users'
,
'users.id'
,
'='
,
'stations.user_id'
)
->
orderby
(
'id'
,
'DESC'
)
->
get
([
'stations.id'
,
'stations.name'
,
'stations.location'
,
'stations.availability'
,
'users.name as uname'
,
'users.email'
,
'users.phone'
]);
$nearestStations
=
[];
// initialize empty array to hold nearest stations
foreach
(
$fuelStations
as
$station
)
{
$queue
=
Queue
::
where
(
'station_id'
,
$station
->
id
)
->
where
(
'status'
,
'0'
)
->
count
();
$distance
=
$this
->
calculateDistance
(
explode
(
":"
,
$station
->
location
)[
0
],
explode
(
":"
,
$station
->
location
)[
1
],
$req
->
lat
,
$req
->
lng
);
$point1
=
explode
(
":"
,
$station
->
location
)[
0
]
.
","
.
explode
(
":"
,
$station
->
location
)[
1
];
$point2
=
$req
->
lat
.
","
.
$req
->
lng
;
$api_distance
=
$this
->
getAPIDistance
(
$point1
,
$point2
,
$req
->
lat
,
$req
->
lng
);
$station
->
distance
=
$distance
;
$station
->
api_distance
=
$api_distance
;
$station
->
queue
=
$queue
;
$nearestStations
[]
=
$station
;
}
usort
(
$nearestStations
,
function
(
$a
,
$b
)
{
if
(
$a
->
distance
==
$b
->
distance
)
{
return
$a
->
queue
-
$b
->
queue
;
}
return
strcmp
(
$a
->
distance
,
$b
->
distance
);
//return $a->distance <=> $b->distance;
});
return
response
()
->
json
([
'respond'
=>
$nearestStations
]);
;
}
public
function
getAPIDistance
(
$point1
,
$point2
){
$key
=
"AIzaSyAqCHZnyToOOkw4fiumXxC5oTEaEVAIISA"
;
$response
=
Http
::
get
(
'https://maps.googleapis.com/maps/api/directions/json?origin='
.
$point1
.
'&destination='
.
$point2
.
'&key='
.
$key
);
...
...
@@ -42,6 +70,8 @@ class StationController extends Controller
}
}
// calculate distance
public
function
calculateDistance
(
$lat1
,
$lon1
,
$lat2
,
$lon2
)
{
$theta
=
$lon1
-
$lon2
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment