You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
王子贤 e810c648fa 增加枚举类型 2 months ago
..
android feat(location_plugin): 初始化位置插件项目 4 months ago
example 优化iM 3 months ago
ios feat(location_plugin): 初始化位置插件项目 4 months ago
lib feat(location_plugin): 初始化位置插件项目 4 months ago
test feat(location_plugin): 初始化位置插件项目 4 months ago
.gitignore feat(location_plugin): 初始化位置插件项目 4 months ago
.metadata feat(location_plugin): 初始化位置插件项目 4 months ago
CHANGELOG.md feat(location_plugin): 初始化位置插件项目 4 months ago
LICENSE feat(location_plugin): 初始化位置插件项目 4 months ago
README.md feat(location_plugin): 初始化位置插件项目 4 months ago
analysis_options.yaml feat(location_plugin): 初始化位置插件项目 4 months ago
pubspec.yaml feat(location_plugin): 初始化位置插件项目 4 months ago

README.md

location_plugin

A Flutter plugin that exposes:

  • getCurrentLocation — backed by native Android (Google Play Services) and iOS (CoreLocation) implementations, returning {latitude, longitude}.
  • getCityInfo — a Dart-side helper that calls Huawei Site reverse-geocode API to translate coordinates into city code and region names.

Usage

final plugin = LocationPlugin();

final location = await plugin.getCurrentLocation();

if (location != null) {
  final lat = location['latitude'];
  final lng = location['longitude'];

  final cityInfo = await plugin.getCityInfo(latitude: lat!, longitude: lng!);
  if (cityInfo != null) {
    debugPrint('code=${cityInfo.code}, region=${cityInfo.region}');
  }
}

The plugin requests runtime permissions when required and surfaces any failures through PlatformException.

Permissions and configuration

Android

  • The plugin declares ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION in its own manifest.
  • Ensure Google Play services are available on the target device.

iOS

  • Add NSLocationWhenInUseUsageDescription to your host app Info.plist.
  • The bundled PrivacyInfo.xcprivacy file declares the required-reason API entry for location (L2). Update it if your use case differs.

Example app

The example/ app fetches the current location on launch and provides a refresh button so you can validate the full flow end-to-end.

Implementation details

  • Android uses the fused location provider (getCurrentLocation with a fallback single update) when Google Play Services are available, and automatically falls back to the platform LocationManager on devices(如部分国内机型)缺少 GMS 的场景。
  • iOS relies on CLLocationManager.requestLocation() and listens for authorization changes before requesting a single fix.
  • getCityInfo posts {lat, lng} to https://siteapi.cloud.huawei.com/mapApi/v1/siteService/reverseGeocode. A default demo key is bundled; supply your own apiKey parameter in production and adjust error handling as needed.

Feel free to extend the plugin with background tracking, geofencing, or reverse-geocoding as needed.