Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
amap_flutter_location
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
amap_flutter_location
Commits
0b48758b
提交
0b48758b
authored
6月 17, 2026
作者:
caoyongfeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加获取 deviceId 功能
上级
de0af76c
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
37 行增加
和
7 行删除
+37
-7
AMapFlutterLocationPlugin.java
.../com/amap/flutter/location/AMapFlutterLocationPlugin.java
+10
-0
AMapLocationClientImpl.java
...ava/com/amap/flutter/location/AMapLocationClientImpl.java
+6
-0
build.gradle
example/android/app/build.gradle
+1
-1
AMapFlutterLocationPlugin.m
ios/Classes/AMapFlutterLocationPlugin.m
+6
-0
amap_flutter_location.dart
lib/amap_flutter_location.dart
+14
-6
没有找到文件。
android/src/main/java/com/amap/flutter/location/AMapFlutterLocationPlugin.java
浏览文件 @
0b48758b
...
...
@@ -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
));
}
/**
* 销毁
*
...
...
android/src/main/java/com/amap/flutter/location/AMapLocationClientImpl.java
浏览文件 @
0b48758b
...
...
@@ -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
);
}
}
example/android/app/build.gradle
浏览文件 @
0b48758b
...
...
@@ -60,5 +60,5 @@ flutter {
}
dependencies
{
implementation
"com.amap.api:location:
5.6.0
"
implementation
"com.amap.api:location:
6.4.9
"
}
ios/Classes/AMapFlutterLocationPlugin.m
浏览文件 @
0b48758b
...
...
@@ -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及以上版本"
);
...
...
lib/amap_flutter_location.dart
浏览文件 @
0b48758b
...
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论