class LiveVehicleTrackingModel {
double lat;
double lng;
int speed;
double refDist;
String refLoc;
String accStatus;
String recDateTime;
String driver;
double temperature;
String imoblize;
LiveVehicleTrackingModel(
{this.lat,
this.lng,
this.speed,
this.refDist,
this.refLoc,
this.accStatus,
this.recDateTime,
this.driver,
this.temperature,
this.imoblize});
LiveVehicleTrackingModel.fromJson(Map<String, dynamic> json) {
lat = json['lat'];
lng = json['lng'];
speed = json['speed'];
refDist = json['refDist'];
refLoc = json['refLoc'];
accStatus = json['accStatus'];
recDateTime = json['recDateTime'];
driver = json['driver'];
temperature = json['temperature'];
imoblize = json['Imoblize'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['lat'] = lat;
data['lng'] = lng;
data['speed'] = speed;
data['refDist'] = refDist;
data['refLoc'] = refLoc;
data['accStatus'] = accStatus;
data['recDateTime'] = recDateTime;
data['driver'] = driver;
data['temperature'] = temperature;
data['Imoblize'] = imoblize;
return data;
}
}
// This is where i am getting location from the Api.
Future<List<LiveVehicleTrackingModel>> getLocations() async {
try {
var url = ApiConstants.liveTrackingApi;
final resp = await http.post(Uri.parse(url));
final responsebody = jsonDecode(resp.body);
return responsebody;
} catch (e) {
return [];
}
}
// 这是我在模型类的帮助下加载位置的第一个问题。
// 列出位置 = []; 经纬度;
loadLocations() async {
List<LiveVehicleTrackingModel> locations;
locations = [];
locations = await getLocations(); //we store the response in a list
for (var i = 0; i < locations.length; i++) {
// LatLng latlng;
latlng = LatLng(
(locations[i].lat),
(locations[i].lng),
);
allMarkers.add(
Marker(
markerId: MarkerId(locations[i].accStatus.toString()),
position: latlng,
),
);
}
// setState(() {
//
// });
}
我已经附加了我的模型类以及我从 api 获取数据的两个函数。但我无法在地图上放置标记。地图只显示空白。请帮帮我