# 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 ```dart 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.