129 lines
5.5 KiB
Dart
129 lines
5.5 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
|
import 'package:get/get.dart';
|
|
//import 'package:google_maps_webservice/directions.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:rogapp/model/destination.dart';
|
|
import 'package:rogapp/pages/destination/destination_controller.dart';
|
|
|
|
import '../utils/const.dart';
|
|
|
|
|
|
class DestinationService{
|
|
|
|
static Future<List<dynamic>> getDestinations(int user_id) async {
|
|
List<dynamic> cats = [];
|
|
String server_url = ConstValues.currentServer();
|
|
String url = "${server_url}/api/destinations/?user_id=${user_id}";
|
|
print('@@@@@@+++ destination_service GETDESTINATIONS - GET, @@@@@@ ${url}');
|
|
final http.Response response = await http.get(
|
|
Uri.parse(url),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
}
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
cats = json.decode(utf8.decode(response.bodyBytes));
|
|
}
|
|
return cats;
|
|
}
|
|
|
|
static Future<Map<String, dynamic>> deleteDestination(int dest_id) async {
|
|
Map<String, dynamic> cats = {};
|
|
String server_url = ConstValues.currentServer();
|
|
String url = "${server_url}/api/delete_destination/?dest_id=${dest_id}";
|
|
print('@@@@@@+++ destination_service DELETEDESTINATION - GET, @@@@@@ ${url}');
|
|
final http.Response response = await http.get(
|
|
Uri.parse(url),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
}
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
cats = json.decode(utf8.decode(response.bodyBytes));
|
|
}
|
|
print("####### ---- ${cats}");
|
|
return cats;
|
|
}
|
|
|
|
static Future<int> updateOrder(int action_id, int order, String dir) async {
|
|
int cats = 0;
|
|
String server_url = ConstValues.currentServer();
|
|
String url = "${server_url}/api/updateorder/?user_action_id=${action_id}&order=${order}&dir=${dir}";
|
|
print('@@@@@@+++ destination_service UPDATEORDER - GET, @@@@@@ ${url}');
|
|
final http.Response response = await http.get(
|
|
Uri.parse(url),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
}
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
cats = json.decode(utf8.decode(response.bodyBytes));
|
|
}
|
|
return cats;
|
|
}
|
|
|
|
static Future<List<PointLatLng>>? getDestinationLine(List<Destination> destinations, Map<String, dynamic> mtx) async{
|
|
PolylinePoints polylinePoints = PolylinePoints();
|
|
|
|
if(destinations.length <= 0){
|
|
return [];
|
|
}
|
|
|
|
//print("##### @@@@@ ${destinations[0].lat}");
|
|
PointLatLng origin = PointLatLng(destinations[0].lat!, destinations[0].lon!);
|
|
PointLatLng dest = PointLatLng(destinations[destinations.length -1].lat!, destinations[destinations.length -1].lon!);
|
|
|
|
|
|
List<PolylineWayPoint> wayPoints = [];
|
|
int i=0;
|
|
for(dynamic d in destinations){
|
|
if(i == 0 || i == (destinations.length -1)){
|
|
i+=1;
|
|
continue;
|
|
}
|
|
double la = d.lat;
|
|
double ln = d.lon;
|
|
|
|
int j = 0;
|
|
|
|
PolylineWayPoint pwp = PolylineWayPoint(location: "${la},${ln}", stopOver: false);
|
|
|
|
|
|
//print("----- UUUUUU ${pwp}");
|
|
//PointLatLng wp = PointLatLng(d["Location"]["geometry"][0][1], d["Location"]["geometry"][0][0]);
|
|
wayPoints.add(pwp);
|
|
i+=1;
|
|
j += 4;
|
|
}
|
|
|
|
final DestinationController destinationController = Get.find<DestinationController>();
|
|
int trav_mode = destinationController.travelMode.value;
|
|
String _mode = "WALKING";
|
|
if(trav_mode == 1){
|
|
//_mode = TravelMode.driving;
|
|
_mode = "DRIVING";
|
|
}
|
|
else if(trav_mode == 2) {
|
|
//_mode = TravelMode.transit;
|
|
_mode = "TRANSIT";
|
|
}
|
|
|
|
|
|
//PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", PointLatLng(35.389282, 136.498027), PointLatLng(36.285848, 137.575186));
|
|
Map<String, dynamic> pl = destinationController.matrix["routes"][0]["overview_polyline"];
|
|
List<PointLatLng> result = polylinePoints.decodePolyline(pl["points"]);
|
|
//List<PointLatLng> result = polylinePoints.decodePolyline("qkyvEq`z`Yp@DBMr@XL@Td@Eb@PREd@IFe@rKIzCY|GEvCBzCHvS@xC?HnBHtBHlBFnBFhGRtDVW~BE`@ICHLk@dE_ClPgAtHu@bFsAhPg@~Ge@bFaEtg@kEpi@oCd\\w@nIw@hGe@fBy@nBqAjC{@zBgBtFOd@M@Wv@i@`BQf@ITKCuE`@yDZqBRCHa@DKG_AHwBRiBR_Fp@y@LYBY]M@KJo@v@M@cAGoGN_Cx@}Cf@}@@mM~@qF`@gCLwBj@sBrAeAhAsAtCoF|MmAbD{@fBwAdBw@p@_Ax@BFOHAl@?`@MAQCEAOIQSaBx@{Ah@eATsAHSB?d@A`D?f@IdWy@AS??V?|BCJ}@?cA?k@Au@wBqDuKQaACg@z@gELg@GK~@uEp@{A@q@y@CHwFHcG?KDqCDK^ABABEH{AE{B{@_Ho@uFIaBFQhBaC@SQSg@k@g@q@Yw@qA{De@}B]uDCsAMEWDqAFu@@^A@TDjA@vDA`CETK|AEtAIFY@o@ALpBZ~HBlCBn@EDGPu@pASJO`@Qf@?ROr@K?qDLHnEUTsDNkENYB{Ab@I^?zA}CrCkBfBw@t@@LwA`Bo@r@eGvD}BrAGGuAj@[?i@rBVi@P}@T?F?^MxDuBhDsBzAcAn@s@zCgDAI~A{A|CsC?{A?UHItA_@DCXC~J_@TUIoEvDKTm@?Y^iALIb@k@f@aAE}AA_BC{@\\Cv@CxAEj@ExCwDDc@CYFANCh@WHEIIRQhB}B|C_E\\w@Hq@JE?a@O}CGkAIwEGmDEmDAKLA^?A}@C{@?e@E_DFQNi@LcB\\eBPsADGKOEWBOH[GCPs@Pq@\\cANs@^q@jAu@fCqAf@]HCXoCV_BVmAZmBVcDBeCCgDAaB?s@RE?aCCaEAyHAoDd@EJiD@_@AaAj@A\\A?Gp@@r@oBXm@LQ?IEy@Fy@tA[n@Gj@Tz@[~ACdAAx@Lp@Kr@]hAa@HAQoCMwCSwGSiGK_CCCKaBCgCOoCOgECwGB_OB{JHkBEmC?yCDyFF{QFue@BsYByE?oAEgAByLBiL?gLBuGXsEd@cCNA?OHa@jAuCn@eAtCyDh@k@v@EvBKr@EEkACUKaC?G~@gAlCeDFBT[jFeGZAfBEh@UpBM`AEMaFjFYIhE?hEPpCJzAPt@Fj@GNUFu@N[FyBbAuB`@_@LEIOB}@HUBQFk@FcAACGQA}@Bi@F@F[Dc@D[FQHELGhBMtDGR?D");
|
|
//PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", origin,dest, travelMode: _mode, wayPoints: wayPoints);
|
|
|
|
//print("#####@@@@@ ${result.points}");
|
|
return result;
|
|
}
|
|
|
|
|
|
}
|
|
|