• Stars
    star
    274
  • Rank 150,274 (Top 3 %)
  • Language
    Dart
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

高德地图flutter定位组件

@@ -1,184 +1,14 @@

amap_location

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一起探讨

A new flutter plugin project.

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
        ]

    }

    ...你的代码

    dependencies {
        /// 注意这里需要在主项目增加一条依赖,否则可能发生编译不通过的情况
        implementation 'com.amap.api:location:latest.integration'
        ...你的代码
    }


集成高德地图定位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
  • 直接获取定位
  • 监听定位改变

下个版本

  • 地理围栏监听

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

More Repositories

1

flutter_swiper

The best swiper for flutter , with multiple layouts, infinite loop. Compatible with Android & iOS.
Dart
3,501
star
2

transformer_page_view

PageTransformer for flutter
Dart
518
star
3

flutter_dropdown_menu

A dropdown menu for Flutter.
Dart
265
star
4

flutter_page_indicator

Page indicator for flutter, with multiple build-in layouts.
Dart
180
star
5

flutter_jpush

Flutter版本jpush
Objective-C
142
star
6

flutter_amap

A Flutter plugin use amap.高德地图flutter组件
Objective-C
136
star
7

flutter_alipay

A flutter plugin to use alipay.
Dart
135
star
8

flutter_refresh

A Flutter plugin for refreshing every scrollable view by pulling down-up.
Dart
71
star
9

flutter_location_picker

A location area picker for flutter 省市区位置选择器
Dart
63
star
10

sweetalert

sweetalert for flutter
Dart
56
star
11

flutter_wechat_ble

ble 4.0 with wechat style api for flutter. flutter版微信api风格的低功耗蓝牙
Dart
53
star
12

gbk2utf8

A flutter package to convert gbk to utf-8
Dart
43
star
13

flutter-lover

我们是一群热爱flutter的开发者,我们的目标是让更多人爱上flutter,让移动开发变得更加高效、简单。
36
star
14

easy_alert

A package for flutter to use alert and toast within one line code.
Dart
32
star
15

disk_lru_cache

Disk lru cache for flutter.
Dart
31
star
16

flutter_baidu_location

A flutter plugin for baidu geo location.百度地图定位flutter插件
Dart
22
star
17

linker

A plugin for flutter to link with other app.
Dart
21
star
18

lazy_indexed_stack

懒加载IndexedStack,IndexedStack默认全部加载children,在某些情况下我们不希望这样,lazy_indexed_stack在index被访问之后才加载对应的视图
Dart
20
star
19

flutter_statusbar

A flutter plugin to fetch statusbar info like height.
Ruby
16
star
20

binding_helper

A easy way to use WidgetsBind like get rect of your widget
Dart
10
star
21

flutter_easy_nfc

nfc for flutter,android only
Java
7
star
22

dva

dva for flutter, flutter版dva。
Dart
4
star
23

flutter_rongcloud

融云im flutter版本,开发中
Dart
4
star
24

flutter_umpush

flutter友盟推送插件
3
star
25

flutter_issue

flutter的问题、坑汇总,总结便于大家查找
3
star
26

puremvc

flutter版本puremvc
Dart
2
star
27

refresh_view

Dart
2
star
28

flutter_awesome

flutter资源整理, flutter教程、flutter开源库、flutter问题汇总、flutter文章
1
star