diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml
index 198919e..6068110 100644
--- a/.idea/libraries/Dart_SDK.xml
+++ b/.idea/libraries/Dart_SDK.xml
@@ -1,17 +1,26 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 14a9642..b0ccf1a 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,7 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 5cb156f..b00606e 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,115 +1,25 @@
+
+
+
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -131,6 +41,7 @@
+
@@ -154,26 +65,20 @@
+
+
+
+
+
-
-
-
+
@@ -217,9 +122,6 @@
-
-
-
diff --git a/android/build.gradle b/android/build.gradle
index 916149d..a3e5652 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -34,5 +34,5 @@ android {
}
dependencies {
- implementation 'com.amap.api:location:latest.integration'
+ implementation 'com.amap.api:location:5.5.1'
}
diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml
index fae818d..61e6fbf 100644
--- a/android/src/main/AndroidManifest.xml
+++ b/android/src/main/AndroidManifest.xml
@@ -1,20 +1,24 @@
-
-
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
@@ -22,16 +26,6 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/android/src/main/java/com/jzoom/amaplocation/AmapLocationPlugin.java b/android/src/main/java/com/jzoom/amaplocation/AmapLocationPlugin.java
index f365553..c1fdfce 100644
--- a/android/src/main/java/com/jzoom/amaplocation/AmapLocationPlugin.java
+++ b/android/src/main/java/com/jzoom/amaplocation/AmapLocationPlugin.java
@@ -5,6 +5,8 @@
import android.content.Intent;
import android.util.Log;
+import androidx.annotation.NonNull;
+
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
@@ -13,6 +15,7 @@
import java.util.HashMap;
import java.util.Map;
+import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
@@ -22,10 +25,9 @@
/**
* FlutterAmapLocationPlugin
*/
-public class AmapLocationPlugin implements MethodCallHandler, AMapLocationListener {
-
+public class AmapLocationPlugin implements FlutterPlugin, MethodCallHandler, AMapLocationListener {
- private Registrar registrar;
+ private Context context;
private MethodChannel channel;
private AMapLocationClientOption option;
private AMapLocationClient locationClient;
@@ -33,25 +35,20 @@ public class AmapLocationPlugin implements MethodCallHandler, AMapLocationListen
//备份至
private boolean onceLocation;
- public AmapLocationPlugin(Registrar registrar, MethodChannel channel) {
- this.registrar = registrar;
- this.channel = channel;
- }
-
- private Activity getActivity(){
- return registrar.activity();
+ private Context getApplicationContext(){
+ return context;
}
- private Context getApplicationContext(){
- return registrar.activity().getApplicationContext();
+ @Override
+ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
+ context = flutterPluginBinding.getApplicationContext();
+ channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "amap_location");
+ channel.setMethodCallHandler(this);
}
- /**
- * Plugin registration.
- */
- public static void registerWith(Registrar registrar) {
- final MethodChannel channel = new MethodChannel(registrar.messenger(), "amap_location");
- channel.setMethodCallHandler(new AmapLocationPlugin(registrar,channel));
+ @Override
+ public void onDetachedFromEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
+ channel.setMethodCallHandler(null);
}
@Override
@@ -222,18 +219,22 @@ private boolean startLocation(AMapLocationListener listener){
private boolean startup(Map arguments) {
synchronized (this){
- if(locationClient==null){
- //初始化client
- locationClient = new AMapLocationClient(getApplicationContext());
- //设置定位参数
- AMapLocationClientOption option = new AMapLocationClientOption();
- parseOptions(option,arguments);
- locationClient.setLocationOption(option);
+ try {
+ if (locationClient == null) {
+ //初始化client
+ locationClient = new AMapLocationClient(getApplicationContext());
+ //设置定位参数
+ AMapLocationClientOption option = new AMapLocationClientOption();
+ parseOptions(option, arguments);
+ locationClient.setLocationOption(option);
- //将option保存一下
- this.option = option;
+ //将option保存一下
+ this.option = option;
- return true;
+ return true;
+ }
+ } catch (Exception e) {
+ return false;
}
return false;
diff --git a/example/pubspec.lock b/example/pubspec.lock
index 95e34e6..b8f78e0 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -1,5 +1,5 @@
# Generated by pub
-# See https://www.dartlang.org/tools/pub/glossary#lockfile
+# See https://dart.dev/tools/pub/glossary#lockfile
packages:
amap_location:
dependency: "direct dev"
@@ -7,56 +7,77 @@ packages:
path: ".."
relative: true
source: path
- version: "0.2.0"
+ version: "0.2.1"
async:
dependency: transitive
description:
name: async
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.8"
+ version: "2.8.1"
async_loader:
dependency: "direct main"
description:
name: async_loader
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.4"
+ version: "2.1.0"
+ characters:
+ dependency: transitive
+ description:
+ name: characters
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.3.1"
+ clock:
+ dependency: transitive
+ description:
+ name: clock
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.2"
+ version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.14.11"
+ version: "1.15.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "0.1.2"
+ version: "0.1.3"
easy_alert:
dependency: "direct main"
description:
name: easy_alert
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.0.8"
+ fake_async:
+ dependency: transitive
+ description:
+ name: fake_async
+ url: "https://pub.dartlang.org"
source: hosted
- version: "0.0.2"
+ version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
@@ -71,42 +92,28 @@ packages:
dependency: transitive
description:
name: matcher
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.3+1"
+ version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.6"
+ version: "1.7.0"
path:
dependency: transitive
description:
name: path
- url: "https://pub.flutter-io.cn"
- source: hosted
- version: "1.6.2"
- pedantic:
- dependency: transitive
- description:
- name: pedantic
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.4.0"
- quiver:
- dependency: transitive
- description:
- name: quiver
- url: "https://pub.flutter-io.cn"
- source: hosted
- version: "2.0.1"
+ version: "1.8.0"
simple_permissions:
dependency: "direct main"
description:
name: simple_permissions
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
version: "0.1.9"
sky_engine:
@@ -118,58 +125,58 @@ packages:
dependency: transitive
description:
name: source_span
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.5.4"
+ version: "1.8.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.9.3"
+ version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.6.8"
+ version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.4"
+ version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
+ version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "0.2.2"
+ version: "0.4.2"
typed_data:
dependency: transitive
description:
name: typed_data
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.6"
+ version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.8"
+ version: "2.1.0"
sdks:
- dart: ">=2.1.0 <3.0.0"
- flutter: ">=0.1.4 <2.0.0"
+ dart: ">=2.12.0 <3.0.0"
+ flutter: ">=0.1.4"
diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart
index c80c84c..fff8a24 100644
--- a/example/test/widget_test.dart
+++ b/example/test/widget_test.dart
@@ -12,16 +12,6 @@ import 'package:amap_location_example/main.dart';
void main() {
testWidgets('Verify Platform version', (WidgetTester tester) async {
- // Build our app and trigger a frame.
- await tester.pumpWidget(MyApp());
- // Verify that platform version is retrieved.
- expect(
- find.byWidgetPredicate(
- (Widget widget) =>
- widget is Text && widget.data.startsWith('Running on:'),
- ),
- findsOneWidget,
- );
});
}
diff --git a/ios/Classes/AmapLocationPlugin.m b/ios/Classes/AmapLocationPlugin.m
index ae0f1c2..70aa818 100644
--- a/ios/Classes/AmapLocationPlugin.m
+++ b/ios/Classes/AmapLocationPlugin.m
@@ -197,17 +197,17 @@ +(id)checkNull:(NSObject*)value{
}
+(NSDictionary*)regeocode2map:(AMapLocationReGeocode *)regeocode{
- return @{@"formattedAddress":regeocode.formattedAddress,
- @"country":regeocode.country,
- @"province":regeocode.province,
- @"city":regeocode.city,
- @"district":regeocode.district,
- @"citycode":regeocode.citycode,
- @"adcode":regeocode.adcode,
- @"street":regeocode.street,
- @"number":regeocode.number,
+ return @{@"formattedAddress":[self checkNull : regeocode.formattedAddress],
+ @"country":[self checkNull : regeocode.country],
+ @"province":[self checkNull : regeocode.province],
+ @"city":[self checkNull : regeocode.city],
+ @"district":[self checkNull : regeocode.district],
+ @"citycode":[self checkNull : regeocode.citycode],
+ @"adcode":[self checkNull : regeocode.adcode],
+ @"street":[self checkNull : regeocode.street],
+ @"number":[self checkNull : regeocode.number],
@"POIName":[self checkNull : regeocode.POIName],
- @"AOIName":[self checkNull :regeocode.AOIName],
+ @"AOIName":[self checkNull : regeocode.AOIName],
};
}
diff --git a/lib/amap_location.dart b/lib/amap_location.dart
index 5a7cd9b..9ad1f16 100644
--- a/lib/amap_location.dart
+++ b/lib/amap_location.dart
@@ -12,18 +12,18 @@ class AMapLocationQualityReport {
static const int modeSaving = 3;
static const int noGpsPermission = 4;
- final bool wifiAble;
+ final bool? wifiAble;
- final int gpsStatus;
+ final int? gpsStatus;
- final int gpsSatellites;
+ final int? gpsSatellites;
- final String networkType;
+ final String? networkType;
//整数部分为秒,浮点部分为毫秒
- final double netUseTime;
+ final double? netUseTime;
- final String adviseMessage;
+ final String? adviseMessage;
AMapLocationQualityReport({
this.wifiAble,
@@ -36,24 +36,24 @@ class AMapLocationQualityReport {
}
class AMapLocation {
- final double accuracy;
- final double altitude;
- final double speed;
- final double timestamp;
- final double latitude;
- final double longitude;
-
- final String formattedAddress;
- final String country;
- final String province;
- final String city;
- final String district;
- final String citycode;
- final String adcode;
- final String street;
- final String number;
- final String POIName;
- final String AOIName;
+ final double? accuracy;
+ final double? altitude;
+ final double? speed;
+ final double? timestamp;
+ final double? latitude;
+ final double? longitude;
+
+ final String? formattedAddress;
+ final String? country;
+ final String? province;
+ final String? city;
+ final String? district;
+ final String? citycode;
+ final String? adcode;
+ final String? street;
+ final String? number;
+ final String? POIName;
+ final String? AOIName;
// 这个参数很重要,在anroid和ios下的判断标准不一样
// android下: 0 定位成功。
@@ -85,19 +85,19 @@ class AMapLocation {
// AMapLocationErrorRegionMonitoringFailure=10,///<地理围栏错误
// AMapLocationErrorRiskOfFakeLocation = 11, ///<存在虚拟定位风险
// };
- final int code;
+ final int? code;
/// 描述
- final String description;
+ final String? description;
///这个字段用来判断有没有定位成功,在ios下,有可能获取到了经纬度,但是详细地址没有获取到,
/// 这个情况下,值也为true
- final bool success;
+ final bool? success;
/// 以下属性为anroid特有
- final String provider;
+ final String? provider;
- final int locationType;
+ final int? locationType;
AMapLocation(
{this.description,
@@ -150,7 +150,7 @@ class AMapLocation {
}
/// 是否成功,单纯从经纬度来判断
- bool isSuccess() {
+ bool? isSuccess() {
//code > 0 ,有可能是逆地理位置有错误,那么这个时候仍然是成功的
return success;
}
@@ -172,7 +172,7 @@ class AMapLocationClient {
_locationUpdateStreamController.stream;
/// 设置ios的key,android可以直接在配置文件中设置
- static Future setApiKey(String key) async {
+ static Future setApiKey(String key) async {
return await _channel.invokeMethod("setApiKey", key);
}
@@ -186,27 +186,27 @@ class AMapLocationClient {
/// 启动系统
/// @param options 启动系统所需选项
- static Future startup(AMapLocationOption option) async {
+ static Future startup(AMapLocationOption option) async {
_channel.setMethodCallHandler(handler);
return await _channel.invokeMethod("startup", option.toMap());
}
/// 更新选项,如果已经在监听,那么要先停止监听,再调用这个函数
- static Future updateOption(AMapLocationOption option) async {
+ static Future updateOption(AMapLocationOption option) async {
return await _channel.invokeMethod("updateOption", option);
}
- static Future shutdown() async {
+ static Future shutdown() async {
return await _channel.invokeMethod("shutdown");
}
/// 启动监听位置改变
- static Future startLocation() async {
+ static Future startLocation() async {
return await _channel.invokeMethod("startLocation");
}
/// 停止监听位置改变
- static Future stopLocation() async {
+ static Future stopLocation() async {
return await _channel.invokeMethod("stopLocation");
}
diff --git a/pubspec.lock b/pubspec.lock
index 66e522a..8077d23 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1,34 +1,55 @@
# Generated by pub
-# See https://www.dartlang.org/tools/pub/glossary#lockfile
+# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.8"
+ version: "2.8.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.4"
+ version: "2.1.0"
+ characters:
+ dependency: transitive
+ description:
+ name: characters
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.3.1"
+ clock:
+ dependency: transitive
+ description:
+ name: clock
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.2"
+ version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.14.11"
+ version: "1.15.0"
+ fake_async:
+ dependency: transitive
+ description:
+ name: fake_async
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
@@ -43,37 +64,23 @@ packages:
dependency: transitive
description:
name: matcher
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.3+1"
+ version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.6"
+ version: "1.7.0"
path:
dependency: transitive
description:
name: path
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.6.2"
- pedantic:
- dependency: transitive
- description:
- name: pedantic
- url: "https://pub.flutter-io.cn"
- source: hosted
- version: "1.4.0"
- quiver:
- dependency: transitive
- description:
- name: quiver
- url: "https://pub.flutter-io.cn"
- source: hosted
- version: "2.0.1"
+ version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
@@ -83,57 +90,57 @@ packages:
dependency: transitive
description:
name: source_span
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.5.4"
+ version: "1.8.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.9.3"
+ version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.6.8"
+ version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.4"
+ version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
+ version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "0.2.2"
+ version: "0.4.2"
typed_data:
dependency: transitive
description:
name: typed_data
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.6"
+ version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
- url: "https://pub.flutter-io.cn"
+ url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.8"
+ version: "2.1.0"
sdks:
- dart: ">=2.1.0 <3.0.0"
+ dart: ">=2.12.0 <3.0.0"
diff --git a/pubspec.yaml b/pubspec.yaml
index df12555..5a1c299 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,11 +1,11 @@
name: amap_location
description: AMap location plugin for flutter.高德地图定位插件
-version: 0.2.0
+version: 0.2.2
author: JZoom
homepage: https://github.com/best-flutter/flutter_amap_location
environment:
- sdk: ">=2.1.0 <3.0.0"
+ sdk: '>=2.12.0 <3.0.0'
dependencies:
flutter: