这是我的数据:
Activity(
name: 'Times Square',
continentType: ContinentType.northAmerica,
description:
'A vibrant intersection and tourist destination in New York City.',
location: const PlaceLocation(
latitude: 40.758896,
longitude: -73.985130,
street: 'Broadway',
city: 'New York City',
country: 'USA'),
),
我想用这个来获取图像:
Future<String> fetchImage(String activityName) async {
final formattedName = activityName.replaceAll(' ', '_');
final formattedLink =
'http://en.wikipedia.org/w/api.php?action=query&titles=$formattedName&prop=pageimages&format=json&pithumbsize=1000';
final response = await http.get(Uri.parse(formattedLink));
final Map<String, dynamic> data =
json.decode(response.body) as Map<String, dynamic>;
final pages = data['query']['pages'];
final pageId = pages.keys.first;
final imageUrl = pages[pageId]['thumbnail']['source'] as String;
return imageUrl;
}
我什至没有找到地图代码。
有什么帮助吗?
我应该得到这样的回复:
{
"batchcomplete": "",
"query": {
"normalized": [
{
"from": "Times_Square",
"to": "Times Square"
}
],
"pages": {
"31389": {
"pageid": 31389,
"ns": 0,
"title": "Times Square",
"thumbnail": {
"source": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/New_york_times_square-terabass.jpg/1000px-New_york_times_square-terabass.jpg",
"width": 1000,
"height": 666
},
"pageimage": "New_york_times_square-terabass.jpg"
}
}
}
}
它与此命令一起使用:
flutter run -d chrome --web-browser-flag“--disable-web-security”
还有更好的解决方案吗?