Skip to content
Snippets Groups Projects
Commit d986b2ca authored by theiled00's avatar theiled00
Browse files

Adjust android setup; setup connection to local running backend

parent ca0c86a3
Branches
No related tags found
1 merge request!6final project merge into main
...@@ -47,7 +47,7 @@ android { ...@@ -47,7 +47,7 @@ android {
applicationId "com.example.router_app" applicationId "com.example.router_app"
// You can update the following values to match your application needs. // You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion minSdkVersion 20
targetSdkVersion flutter.targetSdkVersion targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
......
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
android:value="2" /> android:value="2" />
<meta-data android:name="com.google.andoid.geo.API_KEY" <meta-data android:name="com.google.andoid.geo.API_KEY"
android:value="AIzaSyAzedQacDEZmyxAOUEEeocvehT8MEdMWys"/> android:value="AIzaSyAzedQacDEZmyxAOUEEeocvehT8MEdMWys"/>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</application>
</manifest> </manifest>
...@@ -214,17 +214,32 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -214,17 +214,32 @@ class _MyHomePageState extends State<MyHomePage> {
var destlon = _destCoordinates.longitude; var destlon = _destCoordinates.longitude;
// Get direction data // Get direction data
final response = await http.get( // No weather or days included for now
Uri.parse( final response = await http.post(
'https://api.openrouteservice.org/v2/directions/driving-car?api_key=${config.OSM_API}&start=$originlon,$originlat&end=$destlon,$destlat', Uri.parse('http://10.0.2.2:8080/route'),
body: jsonEncode(
{
"start_node": {
"lat": originlat,
"lon": originlon
},
"end_node": {
"lat": destlat,
"lon": destlon
},
"forbidden": [],
"start_after_today": 0,
"end_after_today": 0
}
), ),
headers: <String, String>{"Content-Type": "application/json"}
); );
_data = jsonDecode(response.body); _data = jsonDecode(response.body);
var coordinates = _data['features'][0]['geometry']['coordinates']; var coordinates = _data['route'];
double duration = int duration = _data['duration'];
_data['features'][0]['properties']['segments'][0]['duration']; int distance = _data['distance'];
double distance = //TODO include day
_data['features'][0]['properties']['segments'][0]['distance']; int daysAfterToday = _data['days_after_today'];
// Format duration and distance // Format duration and distance
_totalDuration = getTotalDuration(duration); _totalDuration = getTotalDuration(duration);
...@@ -260,12 +275,11 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -260,12 +275,11 @@ class _MyHomePageState extends State<MyHomePage> {
// Draw polyline based on given coordinates // Draw polyline based on given coordinates
for (int i = 0; i < ls.lineString.length; i++) { for (int i = 0; i < ls.lineString.length; i++) {
_polyline.add(latlng.LatLng(ls.lineString[i][1], ls.lineString[i][0])); _polyline.add(latlng.LatLng(ls.lineString[i][0], ls.lineString[i][1]));
} }
} }
String getTotalDuration(double duration) { String getTotalDuration(int durationInMins) {
double durationInMins = duration / 60;
int hours = (durationInMins / 60).floor(); int hours = (durationInMins / 60).floor();
int min = (durationInMins % 60).floor(); int min = (durationInMins % 60).floor();
if (hours != 0) { if (hours != 0) {
...@@ -274,7 +288,7 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -274,7 +288,7 @@ class _MyHomePageState extends State<MyHomePage> {
return '$min mins'; return '$min mins';
} }
String getTotalDistance(double distance) { String getTotalDistance(int distance) {
int distanceInKm = (distance / 1000).ceil(); int distanceInKm = (distance / 1000).ceil();
return '$distanceInKm km'; return '$distanceInKm km';
} }
...@@ -954,8 +968,9 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -954,8 +968,9 @@ class _MyHomePageState extends State<MyHomePage> {
itemCount: 1, itemCount: 1,
padding: EdgeInsets.all(20), padding: EdgeInsets.all(20),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return Expanded( return Stack(
child: Column( children: [
Column(
children: [ children: [
Container( Container(
margin: EdgeInsets.only(bottom: 15, top: 5), margin: EdgeInsets.only(bottom: 15, top: 5),
...@@ -1231,6 +1246,7 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -1231,6 +1246,7 @@ class _MyHomePageState extends State<MyHomePage> {
), ),
], ],
), ),
],
); );
}, },
), ),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment