flutter_amap_location_plugin

pub package

A amap Flutter plugin to easily handle realtime location in iOS and Android.

Direct acquisition of location and monitoring location.

Add Dependency

dependencies:
  flutter_amap_location_plugin: ^1.0.0

Getting Started

Android

1、Apply ApiKey reference: https://lbs.amap.com/api/android-sdk/guide/create-project/get-key

2、Configuration ApiKey in project android directory/app/build.gradle -> 'android/defaultConfig' add add the amap key configuration.

 defaultConfig {
         .....
         minSdkVersion 16
         targetSdkVersion 28
         versionCode flutterVersionCode.toInteger()
         versionName flutterVersionName
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 
         manifestPlaceholders = [
             LOCATION_APP_KEY : "xxxxxx", /// amap ApiKey
         ]
     }

IOS

1、Apply ApiKey reference: https://lbs.amap.com/api/android-sdk/guide/create-project/get-key

2、Configuration ApiKey Set ApiKey in main.dart

void main() {

  FlutterAmapLocationPlugin.setApiKey("xxx");

  runApp(MyApp());

  
}

3、Update info.plist reference: https://lbs.amap.com/api/ios-location-sdk/guide/get-location/backgroundlocation

Add an application for targeting permission in the field of info.plist

##Usage

Add Dependency

dependencies:
  flutter_amap_location_plugin: ^1.0.0

Initialize in initState.

@override
  void initState() {
    super.initState();
    //启动客户端,这里设置ios端的精度小一点
    FlutterAmapLocationPlugin.startup(
      AMapLocationOption(
        iosOption: IosAMapLocationOption(
          locatingWithReGeocode: true,
          desiredAccuracy: CLLocationAccuracy.kCLLocationAccuracyHundredMeters,
        ),
      ),
    );
  }

Shutdown in dispose

@override
  void dispose() {
    super.dispose();
    //注意这里关闭
    FlutterAmapLocationPlugin.shutdown();
  }

Get Location Once

AMapLocation location =
        await FlutterAmapLocationPlugin.getLocation();
    print(
        "location = ${location.longitude},${location.latitude},${location.address}");

Listener Location


void startLocation() {
    FlutterAmapLocationPlugin.onLocationUpdate.listen((AMapLocation loc) {
      if (!mounted) return;
      print("location =${location.longitude},${location.latitude},${location.address}");
    });

    FlutterAmapLocationPlugin.startLocation();
  }
  
  @override
  void dispose() {
    super.dispose();

    FlutterAmapLocationPlugin.stopocation();

  }

Libraries

amap_location_option
flutter_amap_location_plugin