xbr_gaode_location 5.0.8 copy "xbr_gaode_location: ^5.0.8" to clipboard
xbr_gaode_location: ^5.0.8 copied to clipboard

高德地图flutter地位内插件,amap_flutter,配合 xbr_gaode_amap 和 xbr_gaode_search 使用

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:xbr_gaode_location/core/location.dart';
import 'package:xbr_gaode_location/xbr_gaode_location.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  int count = 0;
  LocationInfo? locationInfo;
  @override
  void initState() {
    super.initState();
    init();

  }

  Future<void> init() async {
    //初始化 建议在App启动时完成
    await XbrGaodeLocation.initKey( androidKey:"0904c47f0bd8d69ab10daf3d500e4df7", iosKey:"");
    //注意这里没有做任何权限,直接启动不会成功
    //显示用户协议 建议在嵌软件使用协议 用户查看协议时调用
    await XbrGaodeLocation.updatePrivacy( hasContains:true, hasShow:true,hasAgree: true);

    startLocation();
  }

  void startLocation(){
    XbrGaodeLocation.instance().execOnceLocation(callback: (LocationInfo locationInfo){
      print("执行单次定位已成功,即将开始后台定位");
      XbrGaodeLocation.instance().startTimeLocation(interval: 16000,backgroundService: true,callback: (LocationInfo locationInfo){
        setState(() {
          count++;
          this.locationInfo = locationInfo;
        });
        print("哈哈:定位回调成功:${count}次;${DateTime.now()}");
        print(locationInfo?.locationTime??"-----------------------------------------------------");
        //连续定位根据配置时间间隔返回
        //建议在地图控件中测试 dev搜索 xbr_gaode_amap
      });
    });
  }

  void startOnceLocation(){
    XbrGaodeLocation.instance().execOnceLocation(callback: (LocationInfo locationInfo){
      //单次定位返回一次
      //建议在地图控件中测试 dev搜索 xbr_gaode_amap
    });
  }


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('正在后台定位'),
        ),
        body: Center(
          child: Text('回调成功:$count次\n${locationInfo?.toJson()}'),
        ),
      ),
    );
  }
}
1
likes
120
points
15
downloads

Publisher

unverified uploader

Weekly Downloads

高德地图flutter地位内插件,amap_flutter,配合 xbr_gaode_amap 和 xbr_gaode_search 使用

Documentation

API reference

License

MulanPSL-2.0 (license)

Dependencies

flutter

More

Packages that depend on xbr_gaode_location

Packages that implement xbr_gaode_location