提交 25203569 authored 作者: 史晓晨's avatar 史晓晨

feat:①调试web获取定位信息②调试js方法(stringify、console)

上级 759ca3bf
......@@ -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精度类型
......
......@@ -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)}");
}));
}));
}
......
......@@ -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, // 是否将定位结果转换为高德坐标
});
}
......
@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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论