geolocator_ohos 0.0.3 copy "geolocator_ohos: ^0.0.3" to clipboard
geolocator_ohos: ^0.0.3 copied to clipboard

The OpenHarmony implementation of geolocator.

geolocator_ohos #

The OpenHarmony implementation of geolocator.

geolocator 在 OpenHarmony 平台的实现。

Usage #

dependencies:
  geolocator: any
  geolocator_ohos: any
copied to clipboard

在你的项目的 module.json5 文件中增加以下权限设置。

    "requestPermissions": [
      {"name" :  "ohos.permission.KEEP_BACKGROUND_RUNNING"},
      {
        "name": "ohos.permission.LOCATION",
        "reason": "$string:EntryAbility_label",
        "usedScene": {
          "abilities": [
            "EntryAbility"
          ],
          "when": "inuse"
        }
      },
      {
        "name": "ohos.permission.APPROXIMATELY_LOCATION",
        "reason": "$string:EntryAbility_label",
        "usedScene": {
          "abilities": [
            "EntryAbility"
          ],
          "when": "inuse"
        }
      },
      {
        "name": "ohos.permission.LOCATION_IN_BACKGROUND",
        "reason": "$string:EntryAbility_label",
        "usedScene": {
          "abilities": [
            "EntryAbility"
          ],
          "when": "inuse"
        }
      },                  
    ]
copied to clipboard

OpenHarmony only #

Common #

CountryCode? countryCode= await geolocatorOhos.getCountryCode();
copied to clipboard

Geocoder #

    final position = await geolocatorOhos.getCurrentPosition(
      locationSettings: const CurrentLocationSettingsOhos(
        priority: LocationRequestPriority.firstFix,
        scenario: LocationRequestScenario.unset,
      ),
    );

    // ohos only
    if (await geolocatorOhos.isGeocoderAvailable()) {
      // 
      var addresses = await geolocatorOhos.getAddressesFromLocation(
        ReverseGeoCodeRequest(
          latitude: position.latitude,
          longitude: position.longitude,
          locale: 'zh',
          maxItems: 1,
        ),
      );

      for (var address in addresses) {
        if (kDebugMode) {
          print('ReverseGeoCode address:$address');
        }
        var position = await geolocatorOhos.getAddressesFromLocationName(
          GeoCodeRequest(description: address.placeName ?? ''),
        );
        if (kDebugMode) {
          print('geoCode position:$position');
        }
      }
    }
copied to clipboard
1
likes
80
points
43
downloads

Publisher

verified publisherharmonycandies.com

Weekly Downloads

2024.09.08 - 2025.03.23

The OpenHarmony implementation of geolocator.

Repository (GitHub)
View/report issues

Topics

#geolocator #ohos #harmony-os #openharmony

Documentation

API reference

License

MIT (license)

Dependencies

flutter, geolocator_platform_interface

More

Packages that depend on geolocator_ohos