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

增加获取 deviceId 功能

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