amap_location 0.1.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 78

pub package

# flutter_amap_location

android preview

ios preview

高德地图定位flutter组件。

目前实现直接获取定位和监听定位功能。

注意:随着flutter版本的提升, 本项目也会随之更新,

感谢群友 @a396901990 ,目前已经修复了因为使用simple_permissions导致ios不能编译使用的问题

xcode10下如果出现 Multiple commands produce这个错误,参考这篇https://www.jianshu.com/p/8a8444acdca5,亲测可以解决。

如果有疑问或者对这个库感兴趣,可以加qq群:854192563一起探讨

Getting Started

集成高德地图定位android版本

1、先申请一个apikey http://lbs.amap.com/api/android-sdk/guide/create-project/get-key

2、修改 你的项目目录/app/build.gradleandroid/defaultConfig节点修改manifestPlaceholders,新增高德地图key配置

android {
    .... 你的代码

    defaultConfig {
        .....
        manifestPlaceholders = [
                AMAP_KEY : "aa9f0cf8574400f2af0078392c556e25", /// 高德地图key
        ]

    }

集成高德地图定位ios版本

1、申请一个key http://lbs.amap.com/api/ios-sdk/guide/create-project/get-key

直接在dart文件中设置key

import 'package:amap_location/amap_location.dart';
   
   void main(){     
       AMapLocationClient.setApiKey("你的key");
     runApp(new MyApp());
   }

2、在info.plist中增加:

注意必须要描述清楚app使用定位的目的,苹果审核的时候要看, 如果写的不清楚,可能会被苹果拒绝上架,作者有过几次惨痛经历 :(

<key>NSLocationWhenInUseUsageDescription</key>
<string>要用定位</string>

怎么用

先导入dart包 修改pubspec.yaml,增加依赖:

dependencies:
  amap_location: 

在要用的地方导入:

import 'package:amap_location/amap_location.dart';

先启动一下

 await AMapLocationClient.startup(new AMapLocationOption( desiredAccuracy:CLLocationAccuracy.kCLLocationAccuracyHundredMeters  ));

直接获取定位:

await AMapLocationClient.getLocation(true)

监听定位


    AMapLocationClient.onLocationUpate.listen((AMapLocation loc){
      if(!mounted)return;
      setState(() {
         ...
      });
    });

    AMapLocationClient.startLocation();

停止监听定位

AMapLocationClient.stopLocation();

不要忘了在app生命周期结束的时候关闭

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

注意点:

在android6以上最好手动获取定位权限

在example中以simple_permissions这个库为例:

void _checkPersmission() async{
    bool hasPermission = await SimplePermissions.checkPermission(Permission.WhenInUseLocation);
    if(!hasPermission){
      bool requestPermissionResult = await SimplePermissions.requestPermission(Permission.WhenInUseLocation);
      if(!requestPermissionResult){
        Alert.alert(context,title: "申请定位权限失败");
        return;
      }
    }
    AMapLocationClient.onLocationUpate.listen((AMapLocation loc) {
      if (!mounted) return;
      setState(() {
        location = getLocationStr(loc);
      });
    });

    AMapLocationClient.startLocation();
  }

特性

  • IOS
  • Android
  • 直接获取定位
  • 监听定位改变

下个版本

  • 地理围栏监听

[0.1.2] - [2018-11-15]

  • 修正ios不能编译的问题,感谢群友@a396901990的PR
  • 修复ios偶然出现AOIName为nil导致程序崩溃的bug

[0.1.1] - [2018-09-11]

  • 修正key的问题

[0.0.7] - [2018-09-10]

  • 将权限内置到lib中

[0.0.3] - [2018-09-10]

  • 修复一些版本适配问题

[0.0.2] - [2018-05-15]

  • 更新README

[0.0.1] - [2018-05-15]

  • ANDROID
  • IOS
  • 直接获取定位
  • 监听定位改变

example/README.md

amap_location_example

Demonstrates how to use the amap_location plugin.

Getting Started

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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


dependencies:
  amap_location: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:amap_location/amap_location.dart';
  
Version Uploaded Documentation Archive
0.1.2 Nov 15, 2018 Go to the documentation of amap_location 0.1.2 Download amap_location 0.1.2 archive
0.1.1 Sep 11, 2018 Go to the documentation of amap_location 0.1.1 Download amap_location 0.1.1 archive
0.1.0 Sep 10, 2018 Go to the documentation of amap_location 0.1.0 Download amap_location 0.1.0 archive
0.0.5 Sep 10, 2018 Go to the documentation of amap_location 0.0.5 Download amap_location 0.0.5 archive
0.0.3 Sep 10, 2018 Go to the documentation of amap_location 0.0.3 Download amap_location 0.0.3 archive
0.0.2 May 16, 2018 Go to the documentation of amap_location 0.0.2 Download amap_location 0.0.2 archive
0.0.1 May 15, 2018 Go to the documentation of amap_location 0.0.1 Download amap_location 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
72
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Nov 15, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as it's primary language. Please use a description that primarily contains characters used when writing English.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.48.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8