GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - amap-demo/amap-location-flutter: 高德定位Flutter插件

BranchesTags
Open more actions menu

Latest commit

 

History

37 Commits
37 Commits

Folders and files

NameName
Last commit message
Last commit date
android
android
 
 
example
example
 
 
ios
ios
 
 
lib
lib
 
 
res/values
res/values
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pubspec.yaml
pubspec.yaml
 
 

Repository files navigation

前述

  1. 高德定位Flutter插件
  2. 高德开放平台官网分别申请Android端和iOS端的key
  3. 如需了解高德定位SDK的相关功能,请参阅Android定位SDK开发指南和iOS定位SDK开发指南
  4. 高德定位Flutter插件内部没有集成动态申请权限插件,您可根据自身需要添加相应的权限申请插件。可以参考permisson_handler插件

使用高德定位Flutter插件

集成高德定位Flutter插件

集成方式:

  • 方式一 github方引用
  1. 在pubspect.yaml的dependencies里添加如下代码
amap_location_flutter_plugin:
  git:
    url: https://github.com/amap-demo/amap-location-flutter.git
  1. 执行flutter packages get等待插件下载完成
  • 方式二 下载到本地引用
  1. 下载高德定位Flutter插件源码
  2. 在本地工程目录下创建plugins目录,将下载的目录复制到plugins目录下
  3. 在pubspect.yaml的dependencies里添加如下代码
amap_location_flutter_plugin:
  path: plugins/amap-location-flutter
  1. 执行flutter packages get等待插件现在完成

常见问题:

1、在iOS设备上运行或者运行iOS工程遇到: Invalid Podfile file: cannot load such file - /flutter/packages/flutter_tools/bin/podhelper

$ rm ios/Podfile
$ flutter build ios

在需要的定位功能的页面中引入定位Flutter插件的dart类

import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart';
import 'package:amap_location_flutter_plugin/amap_location_option.dart';

接口说明

设置APIKey

///设置Android和iOS的apikey,建议在开始定位之前设置
///[androidKey] Android平台的key
///[iosKey] ios平台的key
static void setApiKey(String androidKey, String iosKey)

申请定位权限

/// 申请定位权限
/// 授予定位权限返回true, 否则返回false
Future<bool> requestLocationPermission()

设置定位参数

 /// 设置定位参数
 void setLocationOption(AMapLocationOption locationOption)

将您设置的参数传递到原生端对外接口,目前支持以下定位参数

 /// 是否需要地址信息,默认true
  bool needAddress = true;

  ///逆地理信息语言类型
  ///默认[GeoLanguage.DEFAULT] 自动适配
  ///可选值:
  ///[GeoLanguage.DEFAULT] 自动适配
  ///[GeoLanguage.EN] 英文
  ///[GeoLanguage.ZH] 中文
  GeoLanguage geoLanguage;

  ///是否单次定位
  ///默认值:false
  bool onceLocation = false;

  ///Android端定位模式, 只在Android系统上有效>
  ///默认值:[AMapLocationMode.Hight_Accuracy]
  ///可选值:
  ///[AMapLocationMode.Battery_Saving]
  ///[AMapLocationMode.Device_Sensors]
  ///[AMapLocationMode.Hight_Accuracy]
  AMapLocationMode locationMode;

  ///Android端定位间隔
  ///单位:毫秒
  ///默认:2000毫秒
  int locationInterval = 2000;

  ///iOS端是否允许系统暂停定位
  ///默认:false
  bool pausesLocationUpdatesAutomatically = false;

  /// iOS端期望的定位精度, 只在iOS端有效
  /// 默认值:最高精度
  /// 可选值:
  /// [DesiredAccuracy.Best] 最高精度
  /// [DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度 
  /// [DesiredAccuracy.NearestTenMeters] 10米 
  /// [DesiredAccuracy.Kilometer] 1000米
  /// [DesiredAccuracy.ThreeKilometers] 3000米<
  DesiredAccuracy desiredAccuracy = DesiredAccuracy.Best;

  /// iOS端定位最小更新距离
  /// 单位:米
  /// 默认值:-1,不做限制
  double distanceFilter = -1;

开始定位

void startLocation()

停止定位

void stopLocation()

销毁定位

高德定位Flutter插件,支持多实例,请在weidet执行dispose()时调用当前定位插件的销毁方法

void destroy()

定位结果获取

原生端以键值对map的形式回传定位结果到Flutter端, 通过onLoationChanged返回定位结果

Stream<Map<String, Object>> onLocationChanged()

注册定位结果监听

_locationPlugin
        .onLocationChanged()
        .listen((Map<String, Object> result) {
          ///result即为定位结果
        }

Getting Started

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

For help on editing plugin code, view the documentation.

About

高德定位Flutter插件

Resources

Readme
BSD-3-Clause license
Activity
Custom properties

Stars

114 stars

Watchers

8 watching

Forks

54 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.