【发布时间】:2021-09-13 10:05:28
【问题描述】:
API 调用由按钮按下触发,此按钮调用 AnchoredMapMarkers 应在预加载的地图上显示纬度/经度图钉
在async 之后返回print('step5.1_APICALL'); 好
错误显示为type 'Future<Stations>' is not a subtype of type 'Iterable<dynamic>'
非常感谢任何帮助
API 调用并以列表形式正常显示 - 我现在尝试从 Json 中提取纬度/经度并将其绘制在我的地图 SDK 上
class MapMarkerExample{
void showAnchoredMapMarkers() {
var stations;
stations = fetchStations();
for (Station stations in stations) {
GeoCoordinates geoCoordinates = GeoCoordinates (stations.place.location.lat, stations.place.location.lng);
_addCircleMapMarker(geoCoordinates, 0);
_addPOIMapMarker(geoCoordinates, 1);
}
}
Future<Stations> fetchStations() async {
print('step5.1_APICALL');
var client = http.Client();
final response = await client.get(
'https://transit.hereapi.com/v8/stations?in=lat,-long&return=transport&apiKey=API_KEY');
if (response.statusCode == 200) {
return Stations.fromJson(jsonDecode(response.body));
} else {
throw Exception('Failed to load stations');
}
}
【问题讨论】: