diff --git a/lib/main.dart b/lib/main.dart index fc7892adbb41cbf980013a259bbaaf5e3bb8ed42..9cf4fb54b09a3904dc5b6a4c4d7a256031bd8a97 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -114,10 +114,33 @@ class _MyHomePageState extends State<MyHomePage> { ); if (result != null) { List<Location> originLoc = await locationFromAddress(result); + + //Match adress with Backend + final response = await http.post( + Uri.parse('http://10.0.2.2:8080/addressmatching'), + body: jsonEncode({"address": result}), + headers: <String, String>{"Content-Type": "application/json"}); + _data = jsonDecode(response.body); + var coordinate = _data["coordinate"]; + print(response.body); + + if (_data.containsKey('error_code') && _data['error_code'] != 0) { + switch (_data['error_code']) { + case 1: + _showMessage( + 'The address is outside the solution space. Please enter an address within Berlin-Brandenburg.', + context); + return; + case 2: + _showMessage('The address could not be found.', context); + return; + } + } + setState(() { originText = result; _originCoordinates = - latlng.LatLng(originLoc[0].latitude, originLoc[0].longitude); + latlng.LatLng(coordinate["lat"], coordinate["lon"]); }); } // Toggle keyboard @@ -259,12 +282,7 @@ class _MyHomePageState extends State<MyHomePage> { if (_data.containsKey('error_code') && _data['error_code'] != 0) { switch (_data['error_code']) { case 1: - _showMessage( - 'The address is outside the solution space. Please enter an address within Berlin-Brandenburg.', - context); - return; - case 2: - _showMessage('The address could not be found.', context); + _showMessage('No route was found.', context); return; } }