Waypoints
parent
24bbe925bc
commit
07ddae0810
|
@ -13,6 +13,7 @@ use App\Station;
|
|||
|
||||
use Validator;
|
||||
use Hash;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class UserPageController extends Controller
|
||||
{
|
||||
|
@ -119,45 +120,96 @@ class UserPageController extends Controller
|
|||
|
||||
public function postTripData(Request $request)
|
||||
{
|
||||
$autonomyKm = $request->autonomyKm;
|
||||
$origin = $request->upOrigin;
|
||||
$destination = $request->upDestination;
|
||||
//https://maps.googleapis.com/maps/api/geocode/json?&latlng=39.6012569,-9.0700634
|
||||
$linkOrigin = "https://maps.googleapis.com/maps/api/geocode/json?address=$origin&key=$this->apiKey";
|
||||
$linkDestination = "https://maps.googleapis.com/maps/api/geocode/json?address=$destination&key=$this->apiKey";
|
||||
$arrayOrigin = json_decode(file_get_contents($linkOrigin, true), true);
|
||||
$arrayDestination = json_decode(file_get_contents($linkDestination, true), true);
|
||||
|
||||
$originDistrict = $arrayOrigin['results'][0]['address_components'][1]['long_name'];
|
||||
$destinationDistrict = $arrayDestination['results'][0]['address_components'][1]['long_name'];
|
||||
|
||||
$originDistrict = trim(str_replace('District', '', $originDistrict));
|
||||
$destinationDistrict = trim(str_replace('District', '', $destinationDistrict));
|
||||
|
||||
$query = Station::join('district', 'station.district', 'district.id')
|
||||
->join('location', 'station.district', 'location.id');
|
||||
//->where(function ($query) {
|
||||
if(strcmp($originDistrict,"Lisbon")==0 && strcmp($destinationDistrict,"Lisbon")!=0){
|
||||
$query->where('district.name', 'like', "%Lisboa%");
|
||||
$query->orWhere('district.name', 'like', "%$destinationDistrict%");
|
||||
}else{
|
||||
if (strcmp($originDistrict, "Lisbon")!=0 && strcmp($destinationDistrict, "Lisbon")==0) {
|
||||
$query->where('district.name', 'like', "%$originDistrict%");
|
||||
$query->orWhere('district.name', 'like', "%Lisboa%");
|
||||
}else{
|
||||
if (strcmp($originDistrict, "Lisbon")==0 && strcmp($destinationDistrict, "Lisbon")==0) {
|
||||
$query->where('district.name', 'like', "%Lisboa%");
|
||||
}else{
|
||||
$query->where('district.name', 'like', "%$originDistrict%");
|
||||
$query->orWhere('district.name', 'like', "%$destinationDistrict%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//});
|
||||
//dd($query);
|
||||
$data = $query->get();
|
||||
echo $data;
|
||||
//print_r( $array['results']);
|
||||
$user = Auth::user();
|
||||
$vehicles = Vehicle::join('vehicles', 'vehicle.id', 'vehicles.vehicle_id')->join('users', 'users.id', 'vehicles.user_id')->where('users.email', $user->email)->get();
|
||||
|
||||
|
||||
return view('user_page', ['name'=>$user->name, 'stations' => $data, 'vehicles' => $vehicles]);
|
||||
}
|
||||
|
||||
public function apiStations($origin, $destination, $autonomyKm) {
|
||||
|
||||
try{
|
||||
$statusCode = 200;
|
||||
$response['stations'] = array();
|
||||
|
||||
|
||||
$linkOrigin = "https://maps.googleapis.com/maps/api/geocode/json?address=$origin&key=$this->apiKey";
|
||||
$linkDestination = "https://maps.googleapis.com/maps/api/geocode/json?address=$destination&key=$this->apiKey";
|
||||
$arrayOrigin = json_decode(file_get_contents($linkOrigin, true), true);
|
||||
$arrayDestination = json_decode(file_get_contents($linkDestination, true), true);
|
||||
|
||||
$originDistrict = $arrayOrigin['results'][0]['address_components'][1]['long_name'];
|
||||
$destinationDistrict = $arrayDestination['results'][0]['address_components'][1]['long_name'];
|
||||
|
||||
$latitudeOrigin = $arrayOrigin['results'][0]['geometry']['location']['lat'];
|
||||
$longitudeOrigin = $arrayOrigin['results'][0]['geometry']['location']['lng'];
|
||||
|
||||
$originDistrict = trim(str_replace('District', '', $originDistrict));
|
||||
$destinationDistrict = trim(str_replace('District', '', $destinationDistrict));
|
||||
|
||||
$query = Station::join('district', 'station.district', 'district.id')
|
||||
->join('location', 'station.district', 'location.id');
|
||||
|
||||
if(strcmp($originDistrict,"Lisbon")==0 && strcmp($destinationDistrict,"Lisbon")!=0){
|
||||
$query->where('district.name', 'like', "%Lisboa%");
|
||||
$query->orWhere('district.name', 'like', "%$destinationDistrict%");
|
||||
}else{
|
||||
if (strcmp($originDistrict, "Lisbon")!=0 && strcmp($destinationDistrict, "Lisbon")==0) {
|
||||
$query->where('district.name', 'like', "%$originDistrict%");
|
||||
$query->orWhere('district.name', 'like', "%Lisboa%");
|
||||
}else{
|
||||
if (strcmp($originDistrict, "Lisbon")==0 && strcmp($destinationDistrict, "Lisbon")==0) {
|
||||
$query->where('district.name', 'like', "%Lisboa%");
|
||||
}else{
|
||||
$query->where('district.name', 'like', "%$originDistrict%");
|
||||
$query->orWhere('district.name', 'like', "%$destinationDistrict%");
|
||||
}
|
||||
}
|
||||
}
|
||||
$query->select("station.id as stationId", "station.name as stationName", "district.name as districtName", "station.brand as brand", "latitude", "longitude");
|
||||
$data = $query->get();
|
||||
foreach ($data as $key => $value) {
|
||||
//echo "$key -> $value->latitude";
|
||||
$latitudeDestination = $value->latitude;
|
||||
$longitudeDestination = $value->longitude;
|
||||
$earthRadius = 6.371;//km
|
||||
|
||||
$latitudeDifference = $latitudeOrigin-$latitudeDestination;
|
||||
$longitudeDifference = $longitudeOrigin-$longitudeDestination;
|
||||
|
||||
$a = pow(sin($latitudeDifference/2),2) + cos($latitudeOrigin) * cos($latitudeDestination) * pow(sin($longitudeDifference/2), 2);
|
||||
$c = 2 * $a * pow(tan(sqrt($a)*sqrt(1-$a)) ,2);
|
||||
$result = $earthRadius * $c;
|
||||
$data[$key]['distance'] = $result;
|
||||
|
||||
|
||||
|
||||
$array =["stationName" => $value->stationName,
|
||||
"stationBrand" => $value->brand,
|
||||
"districtName" => $value->districtName,
|
||||
"latitude" => $value->latitude,
|
||||
"longitude" => $value->longitude
|
||||
];
|
||||
array_push($response["stations"], $array /*[
|
||||
'id' => $district->id,*/
|
||||
//'name' =>
|
||||
//]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}catch (Exception $e){
|
||||
$statusCode = 400;
|
||||
}finally{
|
||||
return Response::json($response, $statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"use strict";
|
||||
var js = $(document).ready(function(){
|
||||
|
||||
var waypts = [];
|
||||
getLocation();
|
||||
|
||||
$("#inputdistrict").autocomplete({
|
||||
|
@ -104,28 +105,26 @@ var js = $(document).ready(function(){
|
|||
|
||||
var markers=new Array();
|
||||
markers.push(getStations());
|
||||
//console.log(markers);
|
||||
//label: labels[labelIndex++ % labels.length],
|
||||
placeMarker(map, markers);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function placeMarker(map, markers) {
|
||||
var myLatLng = {"lat": 39.7495, "lng":-8.8077};
|
||||
var labels = '12345';
|
||||
var labelIndex = 0;
|
||||
|
||||
markers.forEach(function(marker){
|
||||
for (var i = 0; i < marker.length; i++) {
|
||||
//console.log(parseFloat(marker[i].latitude)+" lng"+ parseFloat(marker[i].longitude));
|
||||
new google.maps.Marker({
|
||||
position: {"lat": parseFloat(marker[i].latitude), "lng": parseFloat(marker[i].longitude)},
|
||||
label: labels[labelIndex++ % labels.length],
|
||||
map: map,
|
||||
title: marker[i].stationName
|
||||
});
|
||||
}
|
||||
map: map,
|
||||
title: marker[i].stationName
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function getLocation() {
|
||||
|
@ -240,20 +239,54 @@ var js = $(document).ready(function(){
|
|||
|
||||
|
||||
|
||||
var markers=new Array();
|
||||
|
||||
$("#upSearch").click(function(){
|
||||
var coordinates = getCoordinates();
|
||||
/*console.table(coordinates.origin);
|
||||
console.table(coordinates.destination);*/
|
||||
|
||||
calculateAndDisplayRoute(directionsService, directionsDisplay);
|
||||
});
|
||||
|
||||
calculateAndDisplayRoute(directionsService, directionsDisplay);
|
||||
markers.push(getStationsUP());
|
||||
|
||||
var myLatLng = {"lat": 39.7495, "lng":-8.8077};
|
||||
var labels = '12345';
|
||||
var labelIndex = 0;
|
||||
|
||||
markers.forEach(function(marker){
|
||||
for (var i = 0; i < marker.length; i++) {
|
||||
//console.log(parseFloat(marker[i].latitude)+" lng"+ parseFloat(marker[i].longitude));
|
||||
var marker = new google.maps.Marker({
|
||||
position: {"lat": parseFloat(marker[i].latitude), "lng": parseFloat(marker[i].longitude)},
|
||||
label: labels[labelIndex++ % labels.length],
|
||||
map: mapUP,
|
||||
title: marker[i].stationName
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
marker.addListener('dblclick', function() {
|
||||
alert("double click"+ marker.position);
|
||||
waypts.push({
|
||||
location:marker.position,
|
||||
stopover: true
|
||||
});
|
||||
calculateAndDisplayRoute(directionsService, directionsDisplay);
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
//placeMarker(mapUP, markers);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function calculateAndDisplayRoute(directionsService, directionsDisplay) {
|
||||
var waypts = [];
|
||||
|
||||
/*var checkboxArray = document.getElementById('waypoints');
|
||||
for (var i = 0; i < checkboxArray.length; i++) {
|
||||
if (checkboxArray.options[i].selected) {
|
||||
|
@ -267,8 +300,8 @@ var js = $(document).ready(function(){
|
|||
//waypts.push({location: "Leiria",stopover: true}, {location: "Lisboa",stopover: true});
|
||||
|
||||
directionsService.route({
|
||||
origin: "Leiria",
|
||||
destination: "Lisboa",
|
||||
origin: $("#upOrigin").val(),
|
||||
destination: $("#upDestination").val(),
|
||||
waypoints: waypts,
|
||||
optimizeWaypoints: true,
|
||||
travelMode: 'DRIVING'
|
||||
|
@ -320,6 +353,34 @@ var js = $(document).ready(function(){
|
|||
return coordinates;
|
||||
}
|
||||
|
||||
function getStationsUP(){
|
||||
var origin = $("#upOrigin").val();
|
||||
var destination = $("#upDestination").val();
|
||||
var autonomy = $("#upAutonomyKm").val();
|
||||
var link= "api/stationsup/"+origin+"/"+destination+"/"+autonomy;
|
||||
var stationsData =null;
|
||||
//console.log(link);
|
||||
$.ajax({
|
||||
async: false,
|
||||
url: link,
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
stationsData = data["stations"];
|
||||
//console.table(stationsData);
|
||||
},
|
||||
|
||||
error: function (textStatus, errorThrown) {
|
||||
console.log("Error getting the station data")
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//console.table(stationsData);
|
||||
return stationsData;
|
||||
|
||||
}
|
||||
|
||||
window.initMap = initMap;
|
||||
window.initMapUP = initMapUP;
|
||||
window.updateVehiclePage = updateVehiclePage;
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
</script>
|
||||
-->
|
||||
<div class="col-sm-6 text-left">
|
||||
<form method="post" action="{{route('sendTripData')}}">
|
||||
|
||||
{{csrf_field()}}
|
||||
<div class="form-group">
|
||||
<label for="inputdefault">Inicio: </label>
|
||||
|
@ -74,15 +74,15 @@
|
|||
</ul>
|
||||
</div>
|
||||
<input type="checkbox" name="highway" id="upHighway">Autoestrada</input>
|
||||
<label>Autonomia (km):<input type="number" name="autonomyKm" ></label><br>
|
||||
<label>Autonomia (l):<input type="number" name="autonomyL" ></label>
|
||||
<label>Consumo (l/km):<input type="number" name="consumption" ></label>
|
||||
<label>Autonomia (km):<input type="number" name="upAutonomyKm" id="upAutonomyKm"></label><br>
|
||||
<label>Autonomia (l):<input type="number" name="upAutonomyL" id="upAutonomyL"></label>
|
||||
<label>Consumo (l/km):<input type="number" name="upConsumption" id="upConsumption"></label>
|
||||
|
||||
<br><br>
|
||||
<div class="center">
|
||||
|
||||
<button type="submit" id="upSearch" class="btn btn-primary btn-lg">Pesquisar</button>
|
||||
</form>
|
||||
<button id="upSearch" class="btn btn-primary btn-lg">Pesquisar</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -56,6 +56,8 @@ Route::post('/showGpsCoordinates', 'LandingController@index');
|
|||
//API
|
||||
Route::get('/api/districts', 'LandingController@apiDistricts')->name('apidistricts');
|
||||
Route::get('/api/stations/{district}/{brand}/{fuelType}', 'LandingController@apiStations')->name('apistations');
|
||||
Route::get('/api/stationsup/{origin}/{destination}/{autonomy}', 'UserPageController@apiStations')->name('apistationsup');
|
||||
|
||||
Route::get('/userpage/edit/{id}', 'UserPageController@edit')->name('editVehicle');
|
||||
Route::post('/userpage', 'UserPageController@postTripData')->name('sendTripData');
|
||||
|
||||
|
|
Loading…
Reference in New Issue