ai_amap 0.1.9

  • Readme
  • Changelog
  • Example
  • Installing
  • new50

ai_amap #

totem


English Document中文文档

注意: #

内嵌高德地图导航组件时,首次启动app进入导航页面时,没有导航声音;请重启app后再次进入,才有导航声音

Effect #

iOS-mapAndroid-map
iosandroid
:-:-

1.安装 #

使用当前包作为依赖库

1. 依赖此库 #

在文件 'pubspec.yaml' 中添加

pub package


dependencies:

  ai_amap: ^version

或者以下方式依赖

dependencies:

  # ai_amap package.
  ai_amap:
    git:
      url: https://github.com/pdliuw/ai_amap.git

2. 安装此库 #

你可以通过下面的命令行来安装此库


$ flutter pub get


你也可以通过项目开发工具通过可视化操作来执行上述步骤

3. 导入此库 #

现在,在你的Dart编辑代码中,你可以使用:


import 'package:ai_amap/ai_amap.dart';

2.使用 #

使用'地图'需要动态申请权限,动态权限推荐:permission_handler

配置权限

Android权限配置:


    <!--
    地图SDK(包含其搜索功能)需要的基础权限
    -->

    <!--允许程序打开网络套接字-->
    <uses-permission android:name="android.permission.INTERNET" />
    <!--允许程序设置内置sd卡的写权限-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!--允许程序获取网络状态-->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!--允许程序访问WiFi网络信息-->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <!--允许程序读写手机状态和身份-->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <!--允许程序访问CellID或WiFi热点来获取粗略的位置-->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    

iOS权限配置:


    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Location permission</string>


iOS支持PlatformView配置:

	
    <key>io.flutter.embedded_views_preview</key>
    <true/>
    

1.使用'地图'的地方中: #

  • 1、使用地图
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: const Text('Plugin example app'),
            ),
            body: Column(
              children: [
                Expanded(
                  child: AiAMapPlatformWidget(),
                ),
              ],
            ),
          ),
        );
      }

LICENSE #

BSD 3-Clause License

Copyright (c) 2020, pdliuw
All rights reserved.

[0.1.9] #

  • Update: example model
  1. fix something,
  2. improve health,

[0.1.8] #

  • add: geoFence

[0.1.7] #

  • add: navi

[0.1.6] #

  • add: geo fence

[0.1.5] #

  • Improve: location something

[0.1.4] #

  • Improve: code style and structure

[0.1.3] #

  • Add: ios location widget

[0.1.2] #

  • Add: android location widget

[0.1.1] #

  • Add: ios map

[0.1.0] #

  • Improve: Health

[0.0.2] #

  • Add: android map

[0.0.1] #

  • Initialize

example/lib/main.dart

import 'package:ai_amap/ai_amap.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

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

///
/// 内嵌高德地图导航组件时,首次启动app进入导航页面时,没有导航声音;请重启app后再次进入,才有导航声音
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _locationInfo = '--';

  bool _enableMyLocation = false;
  bool _onPlatformViewCreated = false;

  AiAMapLocationPlatformWidgetController _locationController;

  AiAMapLocationPlatformWidget _aMapWidget;

  @override
  void initState() {
    super.initState();

    _locationController = AiAMapLocationPlatformWidgetController(
      locationResultCallback:
          (AiAMapLocationResult locationResult, bool isSuccess) {
        setState(() {
          print(
              "定位成功:${locationResult.haveAddress()},${locationResult.latitude},${locationResult.longitude}");
          _locationInfo = "${locationResult.country}";
        });
      },
      geoFenceFinishResultCallback: (GeoFenceFinishedResult result) {
        print("添加地理围栏:\n${result.toString()}");
      },
      geoFenceReceiveResultCallback: (GeoFenceReceiveResult result) {
        print("触发地理围栏:\n${result.toString()}");
      },
      platformViewCreatedCallback: (int id) {
        setState(() {
          _onPlatformViewCreated = true;
          requestPermission();
        });
      },
    );

    _aMapWidget = AiAMapLocationPlatformWidget(
      platformWidgetController: _locationController,
    );
  }

  @override
  void dispose() {
    super.dispose();

    _locationController.stopLocation();
    _locationController.destroyLocationService();
  }

  requestPermission() async {
    if (await Permission.locationAlways.request().isGranted) {
      if (await Permission.storage.request().isGranted) {
        if (await Permission.phone.request().isGranted) {
          if (await Permission.microphone.request().isGranted) {
            // Either the permission was already granted before or the user just granted it.
            //1、ApiKey
            AiAMapLocationPlatformWidgetController.setApiKey(
                apiKey: "c3e5689ab4b37aa36b56be87c5aa10b5");
            //2、初始化定位服务
            _locationController..recreateLocationService();
            _locationController.startLocation();

            _locationController.recreateGeoFenceClient();
            //默认设置:北京锋创科技园的经纬度地址
            _locationController.addGeoFence(
                latitude: 39.780718,
                longitude: 116.56848,
                radius: 500,
                customId: "定制化的业务自定义ID");
          }
        }
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [
            Card(
              child: ListTile(
                title: Text("显示我的位置"),
                trailing: _onPlatformViewCreated
                    ? Switch(
                        value: _enableMyLocation,
                        onChanged: (enable) {
                          setState(() {
                            _enableMyLocation = enable;
                            if (enable) {
                              _locationController.showMyLocationIndicator();
                            } else {
                              _locationController.hideMyLocationIndicator();
                            }
                          });
                        })
                    : Text("Hello"),
              ),
            ),
            Text("${_locationInfo ?? '定位中....'}"),
            FlatButton(
              onPressed: () {
                _locationController.startLocation();
              },
              child: Text("开始定位"),
            ),
            FlatButton(
              onPressed: () {
                _locationController.stopLocation();
              },
              child: Text("停止定位"),
            ),
            FlatButton(
              onPressed: () {
                _locationController.startNavigatorWidget();
              },
              child: Text("启动导航组件"),
            ),
            Expanded(
              child: _aMapWidget,
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ai_amap: ^0.1.9

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ai_amap/ai_amap.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:ai_amap/ai_amap.dart that declares support for platforms: android, ios, macos

Package does not support Flutter platform web

Because:

  • package:ai_amap/ai_amap.dart that declares support for platforms: android, ios, macos

Package does not support Flutter platform windows

Because:

  • package:ai_amap/ai_amap.dart that declares support for platforms: android, ios, macos

Package not compatible with SDK dart

Because:

  • ai_amap that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test