update for flutter_map
This commit is contained in:
@ -1,103 +1,103 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||
//import 'package:google_maps_webservice/directions.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
// import 'dart:convert';
|
||||
// import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||
// //import 'package:google_maps_webservice/directions.dart';
|
||||
// import 'package:http/http.dart' as http;
|
||||
// import 'package:rogapp/model/destination.dart';
|
||||
|
||||
import '../utils/const.dart';
|
||||
// import '../utils/const.dart';
|
||||
|
||||
|
||||
class DestinationService{
|
||||
// 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}";
|
||||
//String url = "http://localhost:8100/api/destinations/?user_id=${user_id}";
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
// 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}";
|
||||
// //String url = "http://localhost:8100/api/destinations/?user_id=${user_id}";
|
||||
// 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;
|
||||
}
|
||||
// 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}";
|
||||
//String url = "http://localhost:8100/api/delete_destination/?dest_id=${dest_id}";
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
// 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}";
|
||||
// //String url = "http://localhost:8100/api/delete_destination/?dest_id=${dest_id}";
|
||||
// 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;
|
||||
}
|
||||
// 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("---- url is ${url} -----");
|
||||
//String url = "http://localhost:8100/api/updateorder/?user_action_id=${action_id}&order=${order}&dir=${dir}";
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
// 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("---- url is ${url} -----");
|
||||
// //String url = "http://localhost:8100/api/updateorder/?user_action_id=${action_id}&order=${order}&dir=${dir}";
|
||||
// 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;
|
||||
}
|
||||
// if (response.statusCode == 200) {
|
||||
// cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
// }
|
||||
// return cats;
|
||||
// }
|
||||
|
||||
static Future<List<PointLatLng>>? getDestinationLine(List<Destination> destinations) async{
|
||||
PolylinePoints polylinePoints = PolylinePoints();
|
||||
// static Future<List<PointLatLng>>? getDestinationLine(List<Destination> destinations) async{
|
||||
// PolylinePoints polylinePoints = PolylinePoints();
|
||||
|
||||
if(destinations.length <= 0){
|
||||
return [];
|
||||
}
|
||||
// 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!);
|
||||
// //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;
|
||||
PolylineWayPoint pwp = PolylineWayPoint(location: "${la},${ln}", stopOver: true);
|
||||
//print("----- UUUUUU ${pwp}");
|
||||
//PointLatLng wp = PointLatLng(d["Location"]["geometry"][0][1], d["Location"]["geometry"][0][0]);
|
||||
wayPoints.add(pwp);
|
||||
i+=1;
|
||||
}
|
||||
//PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", PointLatLng(35.389282, 136.498027), PointLatLng(36.285848, 137.575186));
|
||||
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", origin,dest, travelMode: TravelMode.driving, wayPoints: wayPoints);
|
||||
//print("#####@@@@@ ${result.points}");
|
||||
return result.points;
|
||||
}
|
||||
// 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;
|
||||
// PolylineWayPoint pwp = PolylineWayPoint(location: "${la},${ln}", stopOver: true);
|
||||
// //print("----- UUUUUU ${pwp}");
|
||||
// //PointLatLng wp = PointLatLng(d["Location"]["geometry"][0][1], d["Location"]["geometry"][0][0]);
|
||||
// wayPoints.add(pwp);
|
||||
// i+=1;
|
||||
// }
|
||||
// //PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", PointLatLng(35.389282, 136.498027), PointLatLng(36.285848, 137.575186));
|
||||
// PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", origin,dest, travelMode: TravelMode.driving, wayPoints: wayPoints);
|
||||
// //print("#####@@@@@ ${result.points}");
|
||||
// return result.points;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
@ -1,47 +1,47 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
// import 'dart:convert';
|
||||
// import 'package:http/http.dart' as http;
|
||||
// import 'package:rogapp/model/destination.dart';
|
||||
|
||||
|
||||
class MatrixService{
|
||||
// class MatrixService{
|
||||
|
||||
static Future<Map<String, dynamic>> getDestinations(List<Destination> destinations) async {
|
||||
// static Future<Map<String, dynamic>> getDestinations(List<Destination> destinations) async {
|
||||
|
||||
String locs = "";
|
||||
String origin = "";
|
||||
int i = 0;
|
||||
for(Destination d in destinations){
|
||||
// String locs = "";
|
||||
// String origin = "";
|
||||
// int i = 0;
|
||||
// for(Destination d in destinations){
|
||||
|
||||
print("---- getting matrix for ${d} ------------");
|
||||
// print("---- getting matrix for ${d} ------------");
|
||||
|
||||
if(i==0){
|
||||
origin = "${d.lat}, ${d.lon}";
|
||||
}
|
||||
// if(i==0){
|
||||
// origin = "${d.lat}, ${d.lon}";
|
||||
// }
|
||||
|
||||
print("lat is ${d.lat}, long is ${d.lon}");
|
||||
locs += "${d.lat}, ${d.lon}|";
|
||||
i++;
|
||||
}
|
||||
// print("lat is ${d.lat}, long is ${d.lon}");
|
||||
// locs += "${d.lat}, ${d.lon}|";
|
||||
// i++;
|
||||
// }
|
||||
|
||||
//print(locs);
|
||||
// //print(locs);
|
||||
|
||||
Map<String, dynamic> cats = {};
|
||||
String url = "https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${locs}&origins=${origin}&key=AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE";
|
||||
print(url);
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
// Map<String, dynamic> cats = {};
|
||||
// String url = "https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${locs}&origins=${origin}&key=AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE";
|
||||
// print(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;
|
||||
}
|
||||
// if (response.statusCode == 200) {
|
||||
// cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
// }
|
||||
// return cats;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user