Location Wikipedia
This example demonstrates how to create a Flutter app that displays a map and retrieves Wikipedia information about selected locations using Maps SDK for Flutter. Users can explore geographic data on a map and search for relevant Wikipedia content.
How It Works
- Main App Setup : The main app initializes GemKit and sets up the primary map screen.
- Wikipedia Integration : The app enables location-based Wikipedia searches, displaying title and content of selected landmarks.
![]() |
---|
Wikipedia information retrieved for the Statue of Liberty |
UI and Map Integration
The following code sets up the main screen with a map and a search button for location-based Wikipedia information.
class MyApp extends StatelessWidget {
const MyApp({super.key});
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Location Wikipedia',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void dispose() {
GemKit.release();
super.dispose();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.deepPurple[900],
title: const Text('Location Wikipedia', style: TextStyle(color: Colors.white)),
actions: [
IconButton(
onPressed: () => _onLocationWikipediaTap(context),
icon: Icon(Icons.search, color: Colors.white),
)
],
),
body: const GemMap(
key: ValueKey("GemMap"),
appAuthorization: projectApiToken,
),
);
}
void _onLocationWikipediaTap(BuildContext context) {
Navigator.of(context).push(MaterialPageRoute<dynamic>(
builder: (context) => const LocationWikipediaPage(),
));
}
}
Wikipedia Data Display
The following code manages the Wikipedia data retrieval and display for the selected location.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:gem_kit/core.dart';
import 'package:gem_kit/search.dart';
class LocationWikipediaPage extends StatefulWidget {
const LocationWikipediaPage({super.key});
State<LocationWikipediaPage> createState() => _LocationWikipediaPageState();
}
class _LocationWikipediaPageState extends State<LocationWikipediaPage> {
void initState() {
super.initState();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: true,
foregroundColor: Colors.white,
title: const Text(
"Location Wikipedia",
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.deepPurple[900],
),
body: FutureBuilder(
future: _getLocationWikipedia(),
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == null) {
return const Center(child: CircularProgressIndicator());
}
return Column(
mainAxisSize: MainAxisSize.max,
children: [
Text(
snapshot.data!.$1,
style: TextStyle(
overflow: TextOverflow.fade,
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
Expanded(
child: SingleChildScrollView(child: Text(snapshot.data!.$2)),
),
],
);
},
),
);
}
Future<(String, String)> _getLocationWikipedia() async {
final searchCompleter = Completer<List<Landmark>>();
SearchService.search(
"Statue of Liberty",
Coordinates(latitude: 0.0, longitude: 0.0),
(err, lmks) {
searchCompleter.complete(lmks);
},
);
final lmk = (await searchCompleter.future).first;
final completer = Completer<ExternalInfo?>();
ExternalInfo.getExternalInfo(
lmk,
onWikiDataAvailable: (externalInfo) => completer.complete(externalInfo),
);
final externalInfo = await completer.future;
final title = externalInfo!.getWikiPageTitle();
final content = externalInfo.getWikiPageDescription();
return (title, content);
}
}
Flutter Examples
Maps SDK for Flutter Examples can be downloaded or cloned with Git.