A Dart package of weather forecast inside Japan.
The following fragment illustrates how to obtain weather info. for a specific location:
final weather = await Weather.fromLocation(lat: 33.1787095, lng: 129.6762743);
if (weather != null) {
print(weather);
}
The process downloads geometry data to detect weather forecast area. And, by default, it downloads the data every time it is required.
To enable the data cache for reusing the data once downloaded, you should pass cacheDirectory
parameter to Weather.fromLocation function:
final weather = await Weather.fromLocation(
lat: 33.1787095, lng: 129.6762743,
cacheDirectory: '/tmp');
For Flutter applications, you can use path_provider to obtain path suitable for such data. Normally, getTemporaryDirectory can be a good choice.
You can replaces the download/cache mechanism by supplying download
parameter to Weather.fromLocation function:
// Illustrates download/cache mechanism using flutter_cache_manager
final weather = await Weather.fromLocation(
lat: 33.1787095, lng: 129.6762743,
download: (url) async {
final file = await DefaultCacheManager().getSingleFile(url);
return await file.readAsString();
});
Basically, the datasets/contents are licensed under CC BY 4.0:
The plugin internally does the following things to obtain weather info. for locations:
-
The library uses pre-generated "area code to bounding box" table to find areas which contains the location in its bounding box.
-
For each area, download the geometry data (topojson data) from 市町村等(気象警報等) 発表区域データ | 気象庁防災情報発表区域データセット and do hit-test to determine whether the area actually contain the location.
-
Obtain area code corresponding to the area.
-
Obtain weather info. corresponding to the area code via 天気予報 API(livedoor 天気互換).
For the step 2, because the geometry data is still