Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
amap_flutter_location
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
amap_flutter_location
Commits
25203569
提交
25203569
authored
1月 15, 2025
作者:
史晓晨
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:①调试web获取定位信息②调试js方法(stringify、console)
上级
759ca3bf
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
31 行增加
和
35 行删除
+31
-35
main.dart
example/lib/main.dart
+1
-19
amap_location_plugin_web.dart
lib/amap_location_plugin_web.dart
+15
-11
amap.dart
lib/web/amap.dart
+3
-5
utils.dart
lib/web/utils.dart
+12
-0
没有找到文件。
example/lib/main.dart
浏览文件 @
25203569
...
...
@@ -23,8 +23,6 @@ class _MyAppState extends State<MyApp> {
AMapFlutterLocation
_locationPlugin
=
new
AMapFlutterLocation
();
String
?
_divId
;
@override
void
initState
()
{
super
.
initState
();
...
...
@@ -53,22 +51,6 @@ class _MyAppState extends State<MyApp> {
/// 动态申请定位权限
requestPermission
();
/// 这里使用时间作为唯一标识
_divId
=
DateTime
.
now
().
toIso8601String
();
DivElement
_element
;
/// 先创建div并注册
// ignore: undefined_prefixed_name
ui
.
platformViewRegistry
.
registerViewFactory
(
_divId
??
""
,
(
int
viewId
)
{
/// 地图需要的Div
_element
=
DivElement
()
..
style
.
width
=
'100%'
..
style
.
height
=
'100%'
..
style
.
margin
=
'0'
;
return
_element
;
});
///设置Android和iOS的apiKey<br>
///key的申请请参考高德开放平台官网说明<br>
///Android: https://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key
...
...
@@ -78,7 +60,7 @@ class _MyAppState extends State<MyApp> {
AMapFlutterLocation
.
setApiKey
(
"1dbf56e2e8a4d0e4cdc2df9efd36bc71"
,
"125a8a531a3a740654c9e75bbefa7beb"
,
"
83f7b7835d1d9d6ab93444950c84c003
"
);
"
f759e608583c169bb23d7817ed05583d
"
);
});
///iOS 获取native精度类型
...
...
lib/amap_location_plugin_web.dart
浏览文件 @
25203569
...
...
@@ -4,6 +4,7 @@
// ignore: avoid_web_libraries_in_flutter
import
'dart:convert'
;
import
'dart:developer'
;
import
'dart:ui'
;
import
'package:amap_flutter_location/amap_location_plugin_platform_interface.dart'
;
...
...
@@ -15,6 +16,7 @@ import 'package:js/js_util.dart';
import
'amap_location_option.dart'
;
import
'web/amap.dart'
;
import
'web/loader.dart'
;
import
'web/utils.dart'
;
/// A web implementation of the TestWebPluginPlatform of the TestWebPlugin plugin.
class
AmapLocationPluginWeb
extends
AmapLocationPluginPlatform
{
...
...
@@ -22,19 +24,26 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform {
AmapLocationPluginWeb
();
late
AMap
_aMap
;
String
?
_pluginKey
;
static
void
registerWith
(
Registrar
registrar
)
{
AmapLocationPluginPlatform
.
instance
=
AmapLocationPluginWeb
();
}
@override
void
initKey
()
{}
void
initKey
()
{
_pluginKey
=
DateTime
.
now
().
millisecondsSinceEpoch
.
toString
();
}
@override
void
updatePrivacyShow
(
bool
hasContains
,
bool
hasShow
)
{}
void
updatePrivacyShow
(
bool
hasContains
,
bool
hasShow
)
{
// 暂无要求
}
@override
void
updatePrivacyAgree
(
bool
hasAgree
)
{}
void
updatePrivacyAgree
(
bool
hasAgree
)
{
// 暂无要求
}
@override
void
setApiKey
(
String
androidKey
,
String
iosKey
,
String
webKey
)
{
...
...
@@ -61,11 +70,8 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform {
return
Stream
.
value
({});
}
@override
void
setLocationOption
(
AMapLocationOption
locationOption
)
{
}
void
setLocationOption
(
AMapLocationOption
locationOption
)
{}
@override
void
startLocation
()
{
...
...
@@ -73,9 +79,7 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform {
GeolocationOptions
_geolocationOptions
=
GeolocationOptions
(
enableHighAccuracy:
false
,
timeout:
10000
,
offset:
[
10
,
20
],
zoomToAccuracy:
true
,
position:
"RB"
,
convert:
true
,
);
var
geolocation
=
Geolocation
(
_geolocationOptions
);
geolocation
.
getCurrentPosition
(
allowInterop
((
status
,
result
)
{
...
...
@@ -87,7 +91,7 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform {
backgroundColor:
const
Color
(
0xB3000000
),
textColor:
Colors
.
white
,
fontSize:
17.0
);
print
(
"=====11111
${status}
${result.message
}
"
);
consoleLog
(
"=====11111
${status}
${stringify(result)
}
"
);
}));
}));
}
...
...
lib/web/amap.dart
浏览文件 @
25203569
...
...
@@ -49,11 +49,9 @@ class Geolocation {
@anonymous
class
GeolocationOptions
{
external
factory
GeolocationOptions
({
bool
enableHighAccuracy
,
num
timeout
,
List
<
int
>
offset
,
bool
zoomToAccuracy
,
String
position
,
bool
enableHighAccuracy
,
// 进行浏览器原生定位的时候是否尝试获取较高精度,可能影响定位效率,默认为false
num
timeout
,
// 定位的超时时间,毫秒
bool
convert
,
// 是否将定位结果转换为高德坐标
});
}
...
...
lib/web/utils.dart
0 → 100644
浏览文件 @
25203569
@JS
()
library
stringify
;
import
'package:js/js.dart'
;
// Calls invoke JavaScript `JSON.stringify(obj)`.
@JS
(
'JSON.stringify'
)
external
String
stringify
(
Object
obj
);
@JS
(
'console.log'
)
external
String
consoleLog
(
Object
obj
);
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论