parseLatLng method
Implementation
Future<Map<String, String>> parseLatLng(String responseBody, String color, int width) async {
// print('this is lat lng 1');
final responseData = jsonDecode(responseBody);
final p = responseData['p'];
String distance = '';
String time = '';
if (p is List && p.isNotEmpty) {
final firstItem = p[0];
if (firstItem is Map) {
// ✅ Extract distance and time from inside p[0]
if (firstItem.containsKey('d')) {
distance = firstItem['d'].toString();
}
if (firstItem.containsKey('t')) {
time = firstItem['t'].toString();
}
if (firstItem['p'] is List) {
final List innerRoute = firstItem['p'];
final List<String> latLngArray = [];
for (var coord in innerRoute) {
if (coord is List && coord.length == 2) {
final lng = coord[0];
final lat = coord[1];
if (lng is num && lat is num) {
latLngArray.add('$lng;$lat');
}
}
}
// print('this is lat lng 2');
// print(latLngArray);
_channel.invokeMethod('addPolyLines', {
'polylineData': latLngArray,
'color': color,
'width': width,
});
}
}
}
return {
'distance': distance,
'time': time,
};
}