I've read and tried every post/vid but nothing is working. Please help a network admin interested in code.
I can't figure out how I get the json object that is returned, to a usable list/string that I can use. I just need Elements -> Distance -> Text & value to a Text widget.
The JSON object that is returned
{
"destination_addresses" : [ "The destination address" ],
"origin_addresses" : [ "The origin address" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "7 m",
"value" : 7
},
"duration" : {
"text" : "1 min.",
"value" : 1
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
Code snippet (deleted previous tries):
Future<String> getLinkForCalculation() async{
var _latUser = "INSERT LATUSER";
var _lonUser = "INSERT LONUSER";
var _latClient = "INSERT LATCLIENT";
var _lonClient = "INSERT LONCLIENT";
var _key = "INSERT_API_KEY";
var link = "https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=$_latUser,$_lonUser&destinations=$_latClient,$_lonClient&key=$_key";
print(link);
return link;
}
Future<List> calculateDistanceFromLink()async{
var link = await getLinkForCalculation();
Dio finalLink = new Dio();
Response distanceData = await finalLink.get(link);
print(distanceData.data);
}
I have read and tried:
- Flutter and Distance Matrix API parsing json (Implemented the class, imported the method loadData() but my app is giving errors all over the place)
- https://medium.com/flutterdevs/parsing-complex-json-in-flutter-b7f991611d3e (Implemented and altered the class to work with my data. Not working again.)
- Unhandled Exception: InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>
- How to Deserialize a list of objects from json in flutter
- Flutter: Get data from a list of json