weather_japan 0.3.0 copy "weather_japan: ^0.3.0" to clipboard
weather_japan: ^0.3.0 copied to clipboard

A weather forecast package inside Japan.

weather_japan #

A Dart package of weather forecast inside Japan.

Easiest sample #

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) {

Data Caching #

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.

Replacing Download/Cache Mechanism #

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();

Dataset Licenses #

Basically, the datasets/contents are licensed under CC BY 4.0:

Internals #

The plugin internally does the following things to obtain weather info. for locations:

  1. The library uses pre-generated "area code to bounding box" table to find areas which contains the location in its bounding box.

  2. For each area, download the geometry data (topojson data) from 市町村等(気象警報等) 発表区域データ | 気象庁防災情報発表区域データセット and do hit-test to determine whether the area actually contain the location.

  3. Obtain area code corresponding to the area.

  4. Obtain weather info. corresponding to the area code via 天気予報 API(livedoor 天気互換).

For the step 2, because the geometry data is still