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

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

上级 759ca3bf
...@@ -23,8 +23,6 @@ class _MyAppState extends State<MyApp> { ...@@ -23,8 +23,6 @@ class _MyAppState extends State<MyApp> {
AMapFlutterLocation _locationPlugin = new AMapFlutterLocation(); AMapFlutterLocation _locationPlugin = new AMapFlutterLocation();
String? _divId;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
...@@ -53,22 +51,6 @@ class _MyAppState extends State<MyApp> { ...@@ -53,22 +51,6 @@ class _MyAppState extends State<MyApp> {
/// 动态申请定位权限 /// 动态申请定位权限
requestPermission(); 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> ///设置Android和iOS的apiKey<br>
///key的申请请参考高德开放平台官网说明<br> ///key的申请请参考高德开放平台官网说明<br>
///Android: https://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key ///Android: https://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key
...@@ -78,7 +60,7 @@ class _MyAppState extends State<MyApp> { ...@@ -78,7 +60,7 @@ class _MyAppState extends State<MyApp> {
AMapFlutterLocation.setApiKey( AMapFlutterLocation.setApiKey(
"1dbf56e2e8a4d0e4cdc2df9efd36bc71", "1dbf56e2e8a4d0e4cdc2df9efd36bc71",
"125a8a531a3a740654c9e75bbefa7beb", "125a8a531a3a740654c9e75bbefa7beb",
"83f7b7835d1d9d6ab93444950c84c003"); "f759e608583c169bb23d7817ed05583d");
}); });
///iOS 获取native精度类型 ///iOS 获取native精度类型
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
// ignore: avoid_web_libraries_in_flutter // ignore: avoid_web_libraries_in_flutter
import 'dart:convert'; import 'dart:convert';
import 'dart:developer';
import 'dart:ui'; import 'dart:ui';
import 'package:amap_flutter_location/amap_location_plugin_platform_interface.dart'; import 'package:amap_flutter_location/amap_location_plugin_platform_interface.dart';
...@@ -15,6 +16,7 @@ import 'package:js/js_util.dart'; ...@@ -15,6 +16,7 @@ import 'package:js/js_util.dart';
import 'amap_location_option.dart'; import 'amap_location_option.dart';
import 'web/amap.dart'; import 'web/amap.dart';
import 'web/loader.dart'; import 'web/loader.dart';
import 'web/utils.dart';
/// A web implementation of the TestWebPluginPlatform of the TestWebPlugin plugin. /// A web implementation of the TestWebPluginPlatform of the TestWebPlugin plugin.
class AmapLocationPluginWeb extends AmapLocationPluginPlatform { class AmapLocationPluginWeb extends AmapLocationPluginPlatform {
...@@ -22,19 +24,26 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform { ...@@ -22,19 +24,26 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform {
AmapLocationPluginWeb(); AmapLocationPluginWeb();
late AMap _aMap; late AMap _aMap;
String? _pluginKey;
static void registerWith(Registrar registrar) { static void registerWith(Registrar registrar) {
AmapLocationPluginPlatform.instance = AmapLocationPluginWeb(); AmapLocationPluginPlatform.instance = AmapLocationPluginWeb();
} }
@override @override
void initKey() {} void initKey() {
_pluginKey = DateTime.now().millisecondsSinceEpoch.toString();
}
@override @override
void updatePrivacyShow(bool hasContains, bool hasShow) {} void updatePrivacyShow(bool hasContains, bool hasShow) {
// 暂无要求
}
@override @override
void updatePrivacyAgree(bool hasAgree) {} void updatePrivacyAgree(bool hasAgree) {
// 暂无要求
}
@override @override
void setApiKey(String androidKey, String iosKey, String webKey) { void setApiKey(String androidKey, String iosKey, String webKey) {
...@@ -61,11 +70,8 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform { ...@@ -61,11 +70,8 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform {
return Stream.value({}); return Stream.value({});
} }
@override @override
void setLocationOption(AMapLocationOption locationOption) { void setLocationOption(AMapLocationOption locationOption) {}
}
@override @override
void startLocation() { void startLocation() {
...@@ -73,9 +79,7 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform { ...@@ -73,9 +79,7 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform {
GeolocationOptions _geolocationOptions = GeolocationOptions( GeolocationOptions _geolocationOptions = GeolocationOptions(
enableHighAccuracy: false, enableHighAccuracy: false,
timeout: 10000, timeout: 10000,
offset: [10, 20], convert: true,
zoomToAccuracy: true,
position: "RB",
); );
var geolocation = Geolocation(_geolocationOptions); var geolocation = Geolocation(_geolocationOptions);
geolocation.getCurrentPosition(allowInterop((status, result) { geolocation.getCurrentPosition(allowInterop((status, result) {
...@@ -87,7 +91,7 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform { ...@@ -87,7 +91,7 @@ class AmapLocationPluginWeb extends AmapLocationPluginPlatform {
backgroundColor: const Color(0xB3000000), backgroundColor: const Color(0xB3000000),
textColor: Colors.white, textColor: Colors.white,
fontSize: 17.0); fontSize: 17.0);
print("=====11111 ${status} ${result.message}"); consoleLog("=====11111 ${status} ${stringify(result)}");
})); }));
})); }));
} }
......
...@@ -49,11 +49,9 @@ class Geolocation { ...@@ -49,11 +49,9 @@ class Geolocation {
@anonymous @anonymous
class GeolocationOptions { class GeolocationOptions {
external factory GeolocationOptions({ external factory GeolocationOptions({
bool enableHighAccuracy, bool enableHighAccuracy, // 进行浏览器原生定位的时候是否尝试获取较高精度,可能影响定位效率,默认为false
num timeout, num timeout, // 定位的超时时间,毫秒
List<int> offset, bool convert, // 是否将定位结果转换为高德坐标
bool zoomToAccuracy,
String position,
}); });
} }
......
@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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论