类型 'Future<Stations>' 不是类型 'Iterable<dynamic>' 的子类型
type 'Future<Stations>' is not a subtype of type 'Iterable<dynamic>'
API 调用由按下按钮触发,此按钮调用 AnchoredMapMarkers,它应在预加载地图
上显示 lat/long 个图钉
Returns print('step5.1_APICALL');
好了 async
错误显示为type 'Future<Stations>' is not a subtype of type 'Iterable<dynamic>'
非常感谢任何帮助
API 调用并以列表形式显示 - 我现在正尝试从 Json 中提取 lat/long 并将其绘制在我的地图 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');
}
}
你不是在等待你的未来。为了使编译器变得更加复杂,您以某种方式拆分了声明和赋值。并重用了一个变量名。
修复:
Future<void> showAnchoredMapMarkers() async {
final stations = await fetchStations();
for (Station station in stations) {
...
你需要等待
Future<void> showAnchoredMapMarkers() async {
var stations = await fetchStations();
for (Station stations in stations) {
GeoCoordinates geoCoordinates = GeoCoordinates (stations.place.location.lat, stations.place.location.lng);
_addCircleMapMarker(geoCoordinates, 0);
_addPOIMapMarker(geoCoordinates, 1);
}
}
API 调用由按下按钮触发,此按钮调用 AnchoredMapMarkers,它应在预加载地图
上显示 lat/long 个图钉Returns print('step5.1_APICALL');
好了 async
错误显示为type 'Future<Stations>' is not a subtype of type 'Iterable<dynamic>'
非常感谢任何帮助
API 调用并以列表形式显示 - 我现在正尝试从 Json 中提取 lat/long 并将其绘制在我的地图 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');
}
}
你不是在等待你的未来。为了使编译器变得更加复杂,您以某种方式拆分了声明和赋值。并重用了一个变量名。
修复:
Future<void> showAnchoredMapMarkers() async {
final stations = await fetchStations();
for (Station station in stations) {
...
你需要等待
Future<void> showAnchoredMapMarkers() async {
var stations = await fetchStations();
for (Station stations in stations) {
GeoCoordinates geoCoordinates = GeoCoordinates (stations.place.location.lat, stations.place.location.lng);
_addCircleMapMarker(geoCoordinates, 0);
_addPOIMapMarker(geoCoordinates, 1);
}
}