Query to load several station data
parent
403bc1e2b5
commit
4827498318
|
@ -16,6 +16,8 @@ use Hash;
|
|||
|
||||
class UserPageController extends Controller
|
||||
{
|
||||
|
||||
private $apiKey = 'AIzaSyDsZDCiU1k6mSuywRRL88xxXY-81RMEU7s';
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
@ -115,4 +117,47 @@ class UserPageController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
public function postTripData(Request $request)
|
||||
{
|
||||
$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']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,5 +15,10 @@ class Station extends Model
|
|||
protected $fillable = [
|
||||
'name', 'brand', 'location', 'fuel_price', 'services', 'last_update', 'schedule'
|
||||
];
|
||||
|
||||
|
||||
public function phone()
|
||||
{
|
||||
return $this->hasOne('App\District');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -83,9 +83,10 @@ var js = $(document).ready(function(){
|
|||
|
||||
}
|
||||
|
||||
function initMap(location) {
|
||||
|
||||
function initMap(location=null) {
|
||||
var coordinates = {"latitude": null, "longitude": null};
|
||||
if(location!=null){
|
||||
if(location!==null){
|
||||
coordinates = {"latitude": location.latitude, "longitude": location.longitude};
|
||||
}else{
|
||||
if($("#latitude").val()!='' && $("#longitude").val()!=''){
|
||||
|
@ -109,11 +110,12 @@ var js = $(document).ready(function(){
|
|||
|
||||
}
|
||||
|
||||
|
||||
function placeMarker(map, markers) {
|
||||
var myLatLng = {"lat": 39.7495, "lng":-8.8077};
|
||||
markers.forEach(function(marker){
|
||||
for (var i = 0; i < marker.length; i++) {
|
||||
console.log(parseFloat(marker[i].latitude)+" lng"+ parseFloat(marker[i].longitude));
|
||||
//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)},
|
||||
map: map,
|
||||
|
@ -215,6 +217,107 @@ var js = $(document).ready(function(){
|
|||
alert("updateVehiclePage");
|
||||
}
|
||||
|
||||
//User Page
|
||||
|
||||
function initMapUP() {
|
||||
var coordinates = {"latitude": null, "longitude": null};
|
||||
|
||||
coordinates = {"latitude": 39.676944, "longitude": -8.1425};
|
||||
|
||||
|
||||
var pt = {lat: parseFloat(coordinates.latitude), lng: parseFloat(coordinates.longitude)};
|
||||
var directionsService = new google.maps.DirectionsService;
|
||||
var directionsDisplay = new google.maps.DirectionsRenderer;
|
||||
|
||||
var mapUP = new google.maps.Map(document.getElementById('mapUP'), {
|
||||
zoom: 10,
|
||||
center: pt
|
||||
});
|
||||
directionsDisplay.setMap(mapUP);
|
||||
|
||||
|
||||
|
||||
|
||||
$("#upSearch").click(function(){
|
||||
var coordinates = getCoordinates();
|
||||
/*console.table(coordinates.origin);
|
||||
console.table(coordinates.destination);*/
|
||||
|
||||
calculateAndDisplayRoute(directionsService, directionsDisplay);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
function calculateAndDisplayRoute(directionsService, directionsDisplay) {
|
||||
var waypts = [];
|
||||
/*var checkboxArray = document.getElementById('waypoints');
|
||||
for (var i = 0; i < checkboxArray.length; i++) {
|
||||
if (checkboxArray.options[i].selected) {
|
||||
waypts.push({
|
||||
location: checkboxArray[i].value,
|
||||
stopover: true
|
||||
});
|
||||
}
|
||||
}*/
|
||||
|
||||
//waypts.push({location: "Leiria",stopover: true}, {location: "Lisboa",stopover: true});
|
||||
|
||||
directionsService.route({
|
||||
origin: "Leiria",
|
||||
destination: "Lisboa",
|
||||
waypoints: waypts,
|
||||
optimizeWaypoints: true,
|
||||
travelMode: 'DRIVING'
|
||||
}, function(response, status) {
|
||||
if (status === 'OK') {
|
||||
console.table(response);
|
||||
directionsDisplay.setDirections(response);
|
||||
var route = response.routes[0];
|
||||
/*var summaryPanel = document.getElementById('directions-panel');
|
||||
summaryPanel.innerHTML = '';
|
||||
// For each route, display summary information.
|
||||
for (var i = 0; i < route.legs.length; i++) {
|
||||
var routeSegment = i + 1;
|
||||
summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment +
|
||||
'</b><br>';
|
||||
summaryPanel.innerHTML += route.legs[i].start_address + ' to ';
|
||||
summaryPanel.innerHTML += route.legs[i].end_address + '<br>';
|
||||
summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
|
||||
}*/
|
||||
} else {
|
||||
window.alert('Directions request failed due to ' + status);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getCoordinates(){
|
||||
var origin = $("#upOrigin").val();
|
||||
var destination = $("#upDestination").val();
|
||||
var key = "AIzaSyDsZDCiU1k6mSuywRRL88xxXY-81RMEU7s";
|
||||
var coordinates = {origin: {latitude:null, longitude:null},destination: {latitude:null, longitude:null} };
|
||||
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: "https://maps.googleapis.com/maps/api/geocode/json?address="+origin+"&key="+key,
|
||||
success: function(data){
|
||||
coordinates.origin.latitude = data.results[0].geometry.location.lat;
|
||||
coordinates.origin.longitude = data.results[0].geometry.location.lng;
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: "https://maps.googleapis.com/maps/api/geocode/json?address="+destination+"&key="+key,
|
||||
success: function(data){
|
||||
coordinates.destination.latitude = data.results[0].geometry.location.lat;
|
||||
coordinates.destination.longitude = data.results[0].geometry.location.lng;
|
||||
}
|
||||
});
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
window.initMap = initMap;
|
||||
window.initMapUP = initMapUP;
|
||||
window.updateVehiclePage = updateVehiclePage;
|
||||
});
|
||||
|
|
|
@ -8,5 +8,7 @@
|
|||
</footer>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
<script src="{{asset('js/javascript.js')}}"></script>
|
||||
</html>
|
||||
|
|
|
@ -12,9 +12,7 @@
|
|||
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{{asset('css/style.css') }}">
|
||||
<script src="{{asset('js/bootstrap3-typeahead.js')}}"></script>
|
||||
<script async defer
|
||||
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDsZDCiU1k6mSuywRRL88xxXY-81RMEU7s&callback=initMap" >
|
||||
</script>
|
||||
|
||||
|
||||
</head>
|
||||
<body><nav class="navbar navbar-inverse">
|
||||
|
|
|
@ -18,7 +18,10 @@
|
|||
<h2 class="center">Pesquisar Postos:</h2>
|
||||
<div class="row">
|
||||
<!--Div esquerda-->
|
||||
@include('map')
|
||||
<div class="col-sm-6">
|
||||
<div id="map" style="width: 500px;height: 500px;"></div>
|
||||
</div>
|
||||
|
||||
<!--Div direita-->
|
||||
<div class="col-sm-6">
|
||||
@if(!isset($stations))
|
||||
|
@ -88,5 +91,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script async defer
|
||||
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDsZDCiU1k6mSuywRRL88xxXY-81RMEU7s&callback=initMap" >
|
||||
</script>
|
||||
@include('footer')
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
<div class="col-sm-6">
|
||||
<div id="map"></div>
|
||||
</div>
|
|
@ -34,13 +34,11 @@
|
|||
</script>
|
||||
|
||||
<br><br><br>
|
||||
@if($planRoute)
|
||||
@include('map')
|
||||
@endif
|
||||
<!--
|
||||
|
||||
|
||||
<div id="divPercurso">
|
||||
<div id="map" class="col-sm-6"></div>
|
||||
<script>
|
||||
<div id="mapUP" class="col-sm-6" style="width: 300px;height: 500px;"></div>
|
||||
<!--<script>
|
||||
function initMap() {
|
||||
var centerPortugal = {lat: 39.676944, lng: -8.1425};
|
||||
var map = new google.maps.Map(document.getElementById('map'), {
|
||||
|
@ -52,17 +50,18 @@
|
|||
<script async defer
|
||||
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDsZDCiU1k6mSuywRRL88xxXY-81RMEU7s&callback=initMap">
|
||||
</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>
|
||||
<input class="form-control" id="inputdefault" type="text">
|
||||
<input class="form-control" id="upOrigin" name="upOrigin" type="text">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="inputdefault">Destino: </label>
|
||||
<input class="form-control" id="inputdefault" type="text">
|
||||
<input class="form-control" id="upDestination" name="upDestination" type="text">
|
||||
</div>
|
||||
|
||||
<div class="dropdown">
|
||||
|
@ -74,15 +73,20 @@
|
|||
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">JavaScript</a></li>
|
||||
</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>
|
||||
|
||||
<br><br>
|
||||
<div class="center">
|
||||
|
||||
<button type="button" class="btn btn-primary btn-lg">Pesquisar</button>
|
||||
|
||||
<button type="submit" id="upSearch" class="btn btn-primary btn-lg">Pesquisar</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
|
||||
<div id="divVeiculos">
|
||||
<div class="col-sm-6">
|
||||
<div class="list-group" id="vehicleList">
|
||||
|
@ -196,4 +200,7 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
<script async defer
|
||||
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDsZDCiU1k6mSuywRRL88xxXY-81RMEU7s&callback=initMapUP" >
|
||||
</script>
|
||||
@include('footer')
|
||||
|
|
|
@ -57,5 +57,6 @@ Route::post('/showGpsCoordinates', 'LandingController@index');
|
|||
Route::get('/api/districts', 'LandingController@apiDistricts')->name('apidistricts');
|
||||
Route::get('/api/stations/{district}/{brand}/{fuelType}', 'LandingController@apiStations')->name('apistations');
|
||||
Route::get('/userpage/edit/{id}', 'UserPageController@edit')->name('editVehicle');
|
||||
Route::post('/userpage', 'UserPageController@postTripData')->name('sendTripData');
|
||||
|
||||
Route::post('/userpage/editPass', 'UserPageController@postCredentials')->name('editPass');
|
||||
|
|
Loading…
Reference in New Issue