summaryrefslogtreecommitdiffstats
path: root/lib/map/map-response.dart
diff options
context:
space:
mode:
authorHritik Chouhan <hritikc3961@gmail.com>2022-09-01 21:47:45 +0200
committerHritik Chouhan <hritikc3961@gmail.com>2022-09-21 12:25:15 +0200
commit0e820517cbcc6d799cf7f23c7041f3f15b732dc0 (patch)
tree93b40a2310e867a2bca5a553dbc0b567f65fb62a /lib/map/map-response.dart
parent03bb9f818d8caad2213e93e25f085b8672e5ceed (diff)
Upload Flutter-Navigation app for IVI
Flutter Navigation app which Shows current location, Route for destination, search for destination in search bar, turn by turn navigation,duration and distance for destination. Used Mapbox api and Flutter_map plugin and integrated with KUKSA.VAL for current location. Update UI ,Removed unused code and remove hard coded access token. Bug-AGL: SPEC-4548 Signed-off-by: Hritik Chouhan <hritikc3961@gmail.com> Change-Id: I7314285f7b9cdc6940175758761fcc8615c5ab0e
Diffstat (limited to 'lib/map/map-response.dart')
-rw-r--r--lib/map/map-response.dart65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/map/map-response.dart b/lib/map/map-response.dart
new file mode 100644
index 0000000..cfc50c2
--- /dev/null
+++ b/lib/map/map-response.dart
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: Apache-2.0
+
+import 'dart:convert';
+
+import 'package:dio/dio.dart';
+import 'package:flutter_navigation/config.dart';
+
+import 'package:http/http.dart' as http;
+import 'package:latlong2/latlong.dart';
+
+
+
+String baseUrl = 'https://api.mapbox.com/directions/v5/mapbox';
+String navType = 'driving';
+
+Dio _dio = Dio();
+
+Future getdrivingRouteUsingMapbox(LatLng source, LatLng destination,ref) async {
+ final config = ref.read(ConfigStateprovider);
+
+ String url =
+ '$baseUrl/$navType/${source.longitude},${source.latitude};${destination.longitude},${destination.latitude}?alternatives=true&continue_straight=true&geometries=geojson&language=en&overview=full&steps=true&access_token=${config.mapboxAccessToken}';
+ try {
+ _dio.options.contentType = Headers.jsonContentType;
+ final responseData = await _dio.get(url);
+ return responseData.data;
+ } catch (e) {
+ print(e);
+ }
+}
+
+Future<Map> getDirectionsAPIResponse(LatLng currentLatLng,LatLng destiLatLng,ref) async {
+
+ final response = await getdrivingRouteUsingMapbox(currentLatLng, destiLatLng,ref);
+
+ if(response != null){
+ Map geometry = response['routes'][0]['geometry'];
+ num duration = response['routes'][0]['duration'];
+ num distance = response['routes'][0]['distance'];
+ Map legs = response['routes'][0]['legs'][0];
+
+ Map modifiedResponse = {
+ "geometry": geometry,
+ "duration": duration,
+ "distance": distance,
+ "legs" : legs,
+ };
+ return modifiedResponse;
+
+ }
+ else{
+ Map map = {};
+ return map;
+ }
+
+}
+
+Future<Map> getAdress(LatLng pos,ref) async{
+ final config = ref.read(ConfigStateprovider);
+
+ var url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/${pos.longitude},${pos.latitude}.json?&access_token=${config.mapboxAccessToken}';
+ http.Response response = await http.get(Uri.parse(url));
+ Map data = json.decode(response.body);
+ return data;
+} \ No newline at end of file