提交 0b48758b authored 作者: caoyongfeng's avatar caoyongfeng

增加获取 deviceId 功能

上级 de0af76c
...@@ -56,6 +56,9 @@ public class AMapFlutterLocationPlugin implements FlutterPlugin, MethodCallHandl ...@@ -56,6 +56,9 @@ public class AMapFlutterLocationPlugin implements FlutterPlugin, MethodCallHandl
case "calculateDistance": case "calculateDistance":
calculateDistance((Map) call.arguments,result); calculateDistance((Map) call.arguments,result);
break; break;
case "getDeviceId":
getDeviceId(result);
break;
default: default:
result.notImplemented(); result.notImplemented();
break; break;
...@@ -108,6 +111,13 @@ public class AMapFlutterLocationPlugin implements FlutterPlugin, MethodCallHandl ...@@ -108,6 +111,13 @@ public class AMapFlutterLocationPlugin implements FlutterPlugin, MethodCallHandl
result.success(distance); result.success(distance);
} }
/**
* 获取高德定位SDK设备标识
*/
private void getDeviceId(Result result) {
result.success(AMapLocationClient.getDeviceId(mContext));
}
/** /**
* 销毁 * 销毁
* *
......
...@@ -53,6 +53,7 @@ public class AMapLocationClientImpl implements AMapLocationListener { ...@@ -53,6 +53,7 @@ public class AMapLocationClientImpl implements AMapLocationListener {
e.printStackTrace(); e.printStackTrace();
} }
if (null != locationOption) { if (null != locationOption) {
locationOption.setLocationCacheEnable(false);
locationClient.setLocationOption(locationOption); locationClient.setLocationOption(locationOption);
locationClient.setLocationListener(this); locationClient.setLocationListener(this);
locationClient.startLocation(); locationClient.startLocation();
...@@ -81,6 +82,7 @@ public class AMapLocationClientImpl implements AMapLocationListener { ...@@ -81,6 +82,7 @@ public class AMapLocationClientImpl implements AMapLocationListener {
locationClient.onDestroy(); locationClient.onDestroy();
locationClient = null; locationClient = null;
} }
} }
public void destroy() { public void destroy() {
...@@ -143,4 +145,8 @@ public class AMapLocationClientImpl implements AMapLocationListener { ...@@ -143,4 +145,8 @@ public class AMapLocationClientImpl implements AMapLocationListener {
locationClient.setLocationOption(locationOption); locationClient.setLocationOption(locationOption);
} }
} }
public String getDeviceId(Context context) {
return AMapLocationClient.getDeviceId(context);
}
} }
...@@ -60,5 +60,5 @@ flutter { ...@@ -60,5 +60,5 @@ flutter {
} }
dependencies { dependencies {
implementation "com.amap.api:location:5.6.0" implementation "com.amap.api:location:6.4.9"
} }
...@@ -74,6 +74,8 @@ ...@@ -74,6 +74,8 @@
} }
}else if ([@"getSystemAccuracyAuthorization" isEqualToString:call.method]) { }else if ([@"getSystemAccuracyAuthorization" isEqualToString:call.method]) {
[self getSystemAccuracyAuthorization:call result:result]; [self getSystemAccuracyAuthorization:call result:result];
} else if ([@"getDeviceId" isEqualToString:call.method]) {
[self getDeviceId:result];
} else if ([@"updatePrivacyStatement" isEqualToString:call.method]) { } else if ([@"updatePrivacyStatement" isEqualToString:call.method]) {
[self updatePrivacyStatement:call.arguments]; [self updatePrivacyStatement:call.arguments];
} else { } else {
...@@ -81,6 +83,10 @@ ...@@ -81,6 +83,10 @@
} }
} }
- (void)getDeviceId:(FlutterResult)result {
result([AMapServices sharedServices].identifier);
}
- (void)updatePrivacyStatement:(NSDictionary *)arguments { - (void)updatePrivacyStatement:(NSDictionary *)arguments {
if ((AMapLocationVersionNumber) < 20800) { if ((AMapLocationVersionNumber) < 20800) {
NSLog(@"当前定位SDK版本没有隐私合规接口,请升级定位SDK到2.8.0及以上版本"); NSLog(@"当前定位SDK版本没有隐私合规接口,请升级定位SDK到2.8.0及以上版本");
......
...@@ -54,9 +54,12 @@ class AMapFlutterLocation { ...@@ -54,9 +54,12 @@ class AMapFlutterLocation {
_methodChannel.invokeMethod('stopLocation', {'pluginKey': _pluginKey}); _methodChannel.invokeMethod('stopLocation', {'pluginKey': _pluginKey});
return; return;
} }
///计算2点之间的距离 ///计算2点之间的距离
Future<double> calculateDistance(double lat1, double lon1, double lat2, double lon2) async { Future<double> calculateDistance(
var result = await _methodChannel.invokeMethod<double>('calculateDistance', {'lat1': lat1, 'lng1': lon1, 'lat2': lat2, 'lng2': lon2}); double lat1, double lon1, double lat2, double lon2) async {
var result = await _methodChannel.invokeMethod<double>('calculateDistance',
{'lat1': lat1, 'lng1': lon1, 'lat2': lat2, 'lng2': lon2});
return result!; return result!;
} }
...@@ -71,6 +74,11 @@ class AMapFlutterLocation { ...@@ -71,6 +74,11 @@ class AMapFlutterLocation {
.invokeMethod('setApiKey', {'android': androidKey, 'ios': iosKey}); .invokeMethod('setApiKey', {'android': androidKey, 'ios': iosKey});
} }
/// 获取高德定位SDK设备标识,用于排查问题时提供。
static Future<String?> getDeviceId() {
return _methodChannel.invokeMethod<String>('getDeviceId');
}
/// 设置定位参数 /// 设置定位参数
void setLocationOption(AMapLocationOption locationOption) { void setLocationOption(AMapLocationOption locationOption) {
Map option = locationOption.getOptionsMap(); Map option = locationOption.getOptionsMap();
...@@ -143,10 +151,10 @@ class AMapFlutterLocation { ...@@ -143,10 +151,10 @@ class AMapFlutterLocation {
newEvent.remove('pluginKey'); newEvent.remove('pluginKey');
_receiveStream?.add(newEvent); _receiveStream?.add(newEvent);
} }
},onError: (Object error) { }, onError: (Object error) {
print('onLocationChanged error: $error'); print('onLocationChanged error: $error');
_receiveStream?.addError(error); _receiveStream?.addError(error);
},onDone: () { }, onDone: () {
print('onLocationChanged done'); print('onLocationChanged done');
_receiveStream?.close(); _receiveStream?.close();
}); });
...@@ -161,8 +169,8 @@ class AMapFlutterLocation { ...@@ -161,8 +169,8 @@ class AMapFlutterLocation {
/// [hasContains] 隐私声明中是否包含高德隐私政策说明<br> /// [hasContains] 隐私声明中是否包含高德隐私政策说明<br>
/// [hasShow] 隐私权政策是否弹窗展示告知用户<br> /// [hasShow] 隐私权政策是否弹窗展示告知用户<br>
static void updatePrivacyShow(bool hasContains, bool hasShow) { static void updatePrivacyShow(bool hasContains, bool hasShow) {
_methodChannel _methodChannel.invokeMethod('updatePrivacyStatement',
.invokeMethod('updatePrivacyStatement', {'hasContains': hasContains, 'hasShow': hasShow}); {'hasContains': hasContains, 'hasShow': hasShow});
} }
/// 设置是否已经取得用户同意,如果未取得用户同意,高德定位SDK将不会工作<br> /// 设置是否已经取得用户同意,如果未取得用户同意,高德定位SDK将不会工作<br>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论