Browse Source

Merge remote-tracking branch 'origin/new_revision_app' into new_revision_app

dart3_last
wurong 2 years ago
parent
commit
aa14a0f876
  1. 74
      lib/address/address_map_page.dart
  2. 40
      lib/home/home_view/quick_order.dart
  3. 8
      lib/main_page.dart
  4. 18
      lib/mine/mine_shop_details.dart
  5. 18
      lib/mine/vip_detail_page.dart
  6. 49
      lib/order/store_selector_page.dart
  7. 24
      lib/settlement/settlement_view/distribution.dart
  8. 25
      lib/union/location_map_page.dart
  9. 40
      lib/union/union_page.dart
  10. 99
      lib/utils/location.dart
  11. 33
      pubspec.lock
  12. 10
      pubspec.yaml

74
lib/address/address_map_page.dart

@ -11,9 +11,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';
import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart';
import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:flutter_bmflocation/flutter_baidu_location_android_option.dart';
import 'package:flutter_bmflocation/flutter_baidu_location_ios_option.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/address.dart'; import 'package:huixiang/retrofit/data/address.dart';
@ -61,42 +59,34 @@ class _AddressMapPage extends State<AddressMapPage> {
if (aMapFlutterLocation == null) { if (aMapFlutterLocation == null) {
aMapFlutterLocation = LocationFlutterPlugin(); aMapFlutterLocation = LocationFlutterPlugin();
aMapFlutterLocation.requestPermission();
aMapFlutterLocation.onResultCallback().listen((event) {
print("event: ${jsonEncode(event)}");
if (event != null &&
event["latitude"] != null &&
event["longitude"] != null) {
city = event["city"];
BMFCoordinate latLng;
if (event["latitude"] is String && event["longitude"] is String) {
latLng = BMFCoordinate(double.tryParse(event["latitude"]),
double.tryParse(event["longitude"]));
} else {
latLng = BMFCoordinate(event["latitude"], event["longitude"]);
}
BMFCalculateUtils.coordConvert(
coordinate: latLng,
fromType: BMF_COORD_TYPE.COMMON,
toType: BMF_COORD_TYPE.BD09LL)
.then((value) {
saveLatLng(value);
if (_mapController != null) {
this.latLng = Platform.isIOS ? value : latLng;
addMarker();
_mapController.updateMapOptions(
BMFMapOptions(
center: latLng,
zoomLevel: 15,
),
);
}
searchPoi(latLng);
});
}
});
} }
aMapFlutterLocation.singleLocationCallback(callback: (BaiduLocation result){
print("event: $result");
if (result != null &&
result.latitude != null &&
result.longitude != null) {
city = result.city;
BMFCoordinate latLng = BMFCoordinate(result.latitude, result.longitude);
BMFCalculateUtils.coordConvert(
coordinate: latLng,
fromType: BMF_COORD_TYPE.COMMON,
toType: BMF_COORD_TYPE.BD09LL)
.then((value) {
saveLatLng(value);
if (_mapController != null) {
this.latLng = Platform.isIOS ? value : latLng;
addMarker();
_mapController.updateMapOptions(
BMFMapOptions(
center: latLng,
zoomLevel: 15,
),
);
}
searchPoi(latLng);
});
}
});
_setLocOption(); _setLocOption();
getLatLng(); getLatLng();
@ -109,12 +99,12 @@ class _AddressMapPage extends State<AddressMapPage> {
BaiduLocationAndroidOption androidOption = new BaiduLocationAndroidOption(); BaiduLocationAndroidOption androidOption = new BaiduLocationAndroidOption();
androidOption.setCoorType("GCJ02"); // androidOption.setCoorType("GCJ02"); //
androidOption.setIsNeedAltitude(true); // androidOption.setIsNeedAltitude(true); //
androidOption.setIsNeedAddres(true); // androidOption.setIsNeedAddress(true); //
androidOption.setIsNeedLocationPoiList(true); // poi信息 androidOption.setIsNeedLocationPoiList(true); // poi信息
androidOption.setIsNeedNewVersionRgc(true); // rgc信息 androidOption.setIsNeedNewVersionRgc(true); // rgc信息
androidOption.setIsNeedLocationDescribe(true); // androidOption.setIsNeedLocationDescribe(true); //
androidOption.setOpenGps(true); // 使gps androidOption.setOpenGps(true); // 使gps
androidOption.setLocationMode(LocationMode.Hight_Accuracy); // androidOption.setLocationMode(BMFLocationMode.hightAccuracy); //
androidOption.setScanspan(0); // androidOption.setScanspan(0); //
Map androidMap = androidOption.getMap(); Map androidMap = androidOption.getMap();
@ -124,9 +114,9 @@ class _AddressMapPage extends State<AddressMapPage> {
iosOption.setIsNeedNewVersionRgc(true); // rgc信息 iosOption.setIsNeedNewVersionRgc(true); // rgc信息
iosOption.setBMKLocationCoordinateType( iosOption.setBMKLocationCoordinateType(
"BMKLocationCoordinateTypeGCJ02"); // "BMKLocationCoordinateTypeGCJ02"); //
iosOption.setActivityType("CLActivityTypeAutomotiveNavigation"); // iosOption.setActivityType(BMFActivityType.automotiveNavigation); //
iosOption.setLocationTimeout(10); // iosOption.setLocationTimeout(10); //
iosOption.setDesiredAccuracy("kCLLocationAccuracyBest"); // iosOption.setDesiredAccuracy(BMFDesiredAccuracy.best); //
iosOption.setReGeocodeTimeout(10); // iosOption.setReGeocodeTimeout(10); //
iosOption.setDistanceFilter(1000); // iosOption.setDistanceFilter(1000); //
iosOption.setAllowsBackgroundLocationUpdates(true); // iosOption.setAllowsBackgroundLocationUpdates(true); //

40
lib/home/home_view/quick_order.dart

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';
import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart';
import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/store/scan.dart'; import 'package:huixiang/store/scan.dart';
@ -100,37 +101,29 @@ class _QuickOrder extends State<QuickOrder> {
} }
startLocation() async { startLocation() async {
Location.getInstance() Location.getInstance().startLocation(context, (BaiduLocation result){
.aMapFlutterLocation if (result != null &&
.onResultCallback() result.latitude != null &&
.listen((event) { result.longitude != null) {
if (event != null && print("location: $result");
event["latitude"] != null && latLng = BMFCoordinate(result.latitude, result.longitude);
event["longitude"] != null) {
print("location: $event");
if (event["latitude"] is String && event["longitude"] is String) {
latLng = BMFCoordinate(double.tryParse(event["latitude"]),
double.tryParse(event["longitude"]));
} else {
latLng = BMFCoordinate(event["latitude"], event["longitude"]);
}
BMFCalculateUtils.coordConvert( BMFCalculateUtils.coordConvert(
coordinate: latLng, coordinate: latLng,
fromType: BMF_COORD_TYPE.BD09LL, fromType: BMF_COORD_TYPE.BD09LL,
toType: BMF_COORD_TYPE.COMMON) toType: BMF_COORD_TYPE.COMMON)
.then((value) { .then((value) {
this.latLng = value; this.latLng = value;
saveLatLng( saveLatLng(
value, event["province"], event["city"], event["district"]); value, result.province, result.city, result.district);
print("union: Location result ${value.latitude} " print("union: Location result ${value.latitude} "
"${value.longitude}"); "${value.longitude}");
Location.getInstance().stopLocation(); Location.getInstance().stopLocation();
queryStore( queryStore(
"${value.latitude}", "${value.latitude}",
"${value.longitude}", "${value.longitude}",
event["province"], result.province,
event["city"], result.city,
event["district"], result.district,
editingController.text); editingController.text);
if (_mapController != null) if (_mapController != null)
_mapController.updateMapOptions(BMFMapOptions( _mapController.updateMapOptions(BMFMapOptions(
@ -139,10 +132,7 @@ class _QuickOrder extends State<QuickOrder> {
)); ));
}); });
} }
}); }).then((value) {});
Location.getInstance().prepareLoc();
Location.getInstance().startLocation(context).then((value) {});
} }
saveLatLng(BMFCoordinate latLng, province, city, district) async { saveLatLng(BMFCoordinate latLng, province, city, district) async {

8
lib/main_page.dart

@ -3,7 +3,7 @@ import 'dart:io';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
@ -193,8 +193,12 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
); );
SharesdkPlugin.regist(shareSDKRegister); SharesdkPlugin.regist(shareSDKRegister);
LocationFlutterPlugin myLocPlugin = LocationFlutterPlugin();
// //
myLocPlugin.setAgreePrivacy(true);
BMFMapSDK.setAgreePrivacy(true);
if (Platform.isIOS) { if (Platform.isIOS) {
LocationFlutterPlugin.setApiKey("ylW2QPlsbERkho7jOgU4GQSeawmdUIoR"); myLocPlugin.authAK("ylW2QPlsbERkho7jOgU4GQSeawmdUIoR");
BMFMapSDK.setApiKeyAndCoordType( BMFMapSDK.setApiKeyAndCoordType(
'ylW2QPlsbERkho7jOgU4GQSeawmdUIoR', 'ylW2QPlsbERkho7jOgU4GQSeawmdUIoR',
BMF_COORD_TYPE.COMMON, BMF_COORD_TYPE.COMMON,

18
lib/mine/mine_shop_details.dart

@ -1,6 +1,7 @@
import 'package:barcode_widget/barcode_widget.dart'; import 'package:barcode_widget/barcode_widget.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/base_data.dart';
@ -83,20 +84,15 @@ class _MineShopDetails extends State<MineShopDetails> {
startLocation() async { startLocation() async {
// EasyLoading.show(status: S.current.zhengzaijiazai); // EasyLoading.show(status: S.current.zhengzaijiazai);
Location.getInstance() Location.getInstance().startLocation(context, (BaiduLocation result){
.aMapFlutterLocation if (result != null &&
.onResultCallback() result.latitude != null &&
.listen((event) { result.longitude != null) {
if (event != null && vipDetail(result.latitude, result.longitude);
event["latitude"] != null &&
event["longitude"] != null) {
vipDetail(event["latitude"], event["longitude"]);
} else { } else {
EasyLoading.dismiss(); EasyLoading.dismiss();
} }
}); }).then((value) {
Location.getInstance().prepareLoc();
Location.getInstance().startLocation(context).then((value) {
if (!value) { if (!value) {
EasyLoading.dismiss(); EasyLoading.dismiss();
refreshController.refreshFailed(); refreshController.refreshFailed();

18
lib/mine/vip_detail_page.dart

@ -1,6 +1,7 @@
import 'package:barcode_widget/barcode_widget.dart'; import 'package:barcode_widget/barcode_widget.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/base_data.dart';
@ -50,20 +51,15 @@ class _VipDetailPage extends State<VipDetailPage> {
startLocation() async { startLocation() async {
// EasyLoading.show(status: S.current.zhengzaijiazai); // EasyLoading.show(status: S.current.zhengzaijiazai);
Location.getInstance() Location.getInstance().startLocation(context, (BaiduLocation result) {
.aMapFlutterLocation if (result != null &&
.onResultCallback() result.latitude != null &&
.listen((event) { result.longitude != null) {
if (event != null && vipDetail(result.latitude, result.longitude);
event["latitude"] != null &&
event["longitude"] != null) {
vipDetail(event["latitude"], event["longitude"]);
} else { } else {
EasyLoading.dismiss(); EasyLoading.dismiss();
} }
}); }).then((value) {
Location.getInstance().prepareLoc();
Location.getInstance().startLocation(context).then((value) {
if (!value) { if (!value) {
EasyLoading.dismiss(); EasyLoading.dismiss();
refreshController.refreshFailed(); refreshController.refreshFailed();

49
lib/order/store_selector_page.dart

@ -6,7 +6,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart';
import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
@ -52,33 +52,27 @@ class _StoreSelectorPage extends State<StoreSelectorPage> {
if (aMapFlutterLocation == null) { if (aMapFlutterLocation == null) {
aMapFlutterLocation = LocationFlutterPlugin(); aMapFlutterLocation = LocationFlutterPlugin();
aMapFlutterLocation.onResultCallback().listen((event) {
if (event != null &&
event["latitude"] != null &&
event["longitude"] != null) {
print("location: $event");
aMapFlutterLocation.stopLocation();
if (event["latitude"] is String && event["longitude"] is String) {
latLng = BMFCoordinate(double.tryParse(event["latitude"]),
double.tryParse(event["longitude"]));
} else {
latLng = BMFCoordinate(event["latitude"], event["longitude"]);
}
BMFCalculateUtils.coordConvert(
coordinate: latLng,
fromType: BMF_COORD_TYPE.COMMON,
toType: BMF_COORD_TYPE.BD09LL)
.then((value) {
this.latLng = value;
saveLatLng(
value, event["province"], event["city"], event["district"]);
queryStore("${value.latitude}", "${value.longitude}",
event["province"], event["city"], event["district"]);
});
}
});
} }
aMapFlutterLocation.singleLocationCallback(callback: (BaiduLocation result) {
if (result != null &&
result.latitude != null &&
result.longitude != null) {
print("location: $result");
aMapFlutterLocation.stopLocation();
latLng = BMFCoordinate(result.latitude, result.longitude);
BMFCalculateUtils.coordConvert(
coordinate: latLng,
fromType: BMF_COORD_TYPE.COMMON,
toType: BMF_COORD_TYPE.BD09LL)
.then((value) {
this.latLng = value;
saveLatLng(
value, result.province, result.city, result.district);
queryStore("${value.latitude}", "${value.longitude}",
result.province, result.city, result.district);
});
}
});
aMapFlutterLocation.prepareLoc({ aMapFlutterLocation.prepareLoc({
"coorType": "bd09ll", "coorType": "bd09ll",
"isNeedAddres": false, "isNeedAddres": false,
@ -95,7 +89,6 @@ class _StoreSelectorPage extends State<StoreSelectorPage> {
"reGeocodeTimeout": 10, "reGeocodeTimeout": 10,
"activityType": "CLActivityTypeAutomotiveNavigation", "activityType": "CLActivityTypeAutomotiveNavigation",
"BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL", "BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL",
"BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL",
"isNeedNewVersionRgc": false, "isNeedNewVersionRgc": false,
}); });

24
lib/settlement/settlement_view/distribution.dart

@ -1,5 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';
import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
@ -54,26 +56,16 @@ class _DistributionMode extends State<DistributionMode> {
/// ///
void startLocation() async { void startLocation() async {
Location.getInstance() Location.getInstance().startLocation(context, (BaiduLocation result){
.aMapFlutterLocation if (result != null &&
.onResultCallback() result.latitude != null &&
.listen((event) { result.longitude != null) {
if (event != null && print("location: $result");
event["latitude"] != null && myLatLng = BMFCoordinate(result.latitude, result.longitude);
event["longitude"] != null) {
print("location: $event");
if (event["latitude"] is String && event["longitude"] is String) {
myLatLng = BMFCoordinate(double.tryParse(event["latitude"]),
double.tryParse(event["longitude"]));
} else {
myLatLng = BMFCoordinate(event["latitude"], event["longitude"]);
}
calculate(); calculate();
Location.getInstance().stopLocation(); Location.getInstance().stopLocation();
} }
}); });
Location.getInstance().prepareLoc();
Location.getInstance().startLocation(context);
} }
calculate() async { calculate() async {

25
lib/union/location_map_page.dart

@ -2,6 +2,7 @@ import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';
import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:huixiang/utils/flutter_utils.dart'; import 'package:huixiang/utils/flutter_utils.dart';
import 'package:huixiang/utils/location.dart'; import 'package:huixiang/utils/location.dart';
import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_appbar.dart';
@ -26,29 +27,19 @@ class _LocationMap extends State<LocationMap> {
startLocation(); startLocation();
} }
void startLocation() async { void startLocation() {
Location.getInstance() Location.getInstance().startLocation(context, (BaiduLocation result) {
.aMapFlutterLocation if (result != null &&
.onResultCallback() result.latitude != null &&
.listen((event) { result.longitude != null) {
if (event != null && print("location: $result");
event["latitude"] != null && myLatLng = BMFCoordinate(result.latitude, result.longitude);
event["longitude"] != null) {
print("location: $event");
if (event["latitude"] is String && event["longitude"] is String) {
myLatLng = BMFCoordinate(double.tryParse(event["latitude"]),
double.tryParse(event["longitude"]));
} else {
myLatLng = BMFCoordinate(event["latitude"], event["longitude"]);
}
AppUtils.coordConvert(myLatLng).then((value) { AppUtils.coordConvert(myLatLng).then((value) {
this.myLatLng = value; this.myLatLng = value;
locationShow(); locationShow();
}); });
} }
}); });
Location.getInstance().prepareLoc();
Location.getInstance().startLocation(context);
} }
locationShow() { locationShow() {

40
lib/union/union_page.dart

@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';
import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart';
import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/main.dart'; import 'package:huixiang/main.dart';
@ -130,37 +131,29 @@ class UnionPageState extends State<UnionPage>
startLocation(bool isOnRefresh) async { startLocation(bool isOnRefresh) async {
if (!isOnRefresh) EasyLoading.show(status: S.current.zhengzaijiazai); if (!isOnRefresh) EasyLoading.show(status: S.current.zhengzaijiazai);
Location.getInstance() Location.getInstance().startLocation(context, (BaiduLocation result) {
.aMapFlutterLocation if (result != null &&
.onResultCallback() result.latitude != null &&
.listen((event) { result.longitude != null) {
if (event != null && print("location: $result");
event["latitude"] != null && latLng = BMFCoordinate(result.latitude, result.longitude);
event["longitude"] != null) {
print("location: $event");
if (event["latitude"] is String && event["longitude"] is String) {
latLng = BMFCoordinate(double.tryParse(event["latitude"]),
double.tryParse(event["longitude"]));
} else {
latLng = BMFCoordinate(event["latitude"], event["longitude"]);
}
BMFCalculateUtils.coordConvert( BMFCalculateUtils.coordConvert(
coordinate: latLng, coordinate: latLng,
fromType: BMF_COORD_TYPE.BD09LL, fromType: BMF_COORD_TYPE.BD09LL,
toType: BMF_COORD_TYPE.COMMON) toType: BMF_COORD_TYPE.COMMON)
.then((value) { .then((value) {
this.latLng = value; this.latLng = value;
saveLatLng( saveLatLng(
value, event["province"], event["city"], event["district"]); value, result.province, result.city, result.district);
print("union: Location result ${value.latitude} " print("union: Location result ${value.latitude} "
"${value.longitude}"); "${value.longitude}");
Location.getInstance().stopLocation(); Location.getInstance().stopLocation();
queryStore( queryStore(
"${value.latitude}", "${value.latitude}",
"${value.longitude}", "${value.longitude}",
event["province"], result.province,
event["city"], result.city,
event["district"], result.district,
"", "",
-1); -1);
if (_mapController != null) if (_mapController != null)
@ -173,10 +166,7 @@ class UnionPageState extends State<UnionPage>
getLatLng(); getLatLng();
// EasyLoading.dismiss(); // EasyLoading.dismiss();
} }
}); }).then((value) {
Location.getInstance().prepareLoc();
Location.getInstance().startLocation(context).then((value) {
if (!value) { if (!value) {
EasyLoading.dismiss(); EasyLoading.dismiss();
tabRefresh().refreshFailed(); tabRefresh().refreshFailed();

99
lib/utils/location.dart

@ -2,11 +2,64 @@ import 'dart:io';
import 'package:android_intent_plus/android_intent.dart'; import 'package:android_intent_plus/android_intent.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/view_widget/request_permission.dart'; import 'package:huixiang/view_widget/request_permission.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
BaiduLocationAndroidOption initAndroidOptions() {
BaiduLocationAndroidOption options = BaiduLocationAndroidOption(
//
locationMode: BMFLocationMode.hightAccuracy,
//
isNeedAddress: true,
//
isNeedAltitude: false,
// poi信息
isNeedLocationPoiList: false,
// rgc信息
isNeedNewVersionRgc: false,
//
isNeedLocationDescribe: true,
// 使gps
openGps: true,
//
locationPurpose: BMFLocationPurpose.signIn,
//
coordType: BMFLocationCoordType.bd09ll,
// int类型ms
// 00
scanspan: 0);
return options;
}
BaiduLocationIOSOption initIOSOptions() {
BaiduLocationIOSOption options = BaiduLocationIOSOption(
//
coordType: BMFLocationCoordType.bd09ll,
//
locationTimeout: 10,
//
reGeocodeTimeout: 10,
// automotiveNavigation
activityType: BMFActivityType.automotiveNavigation,
// best
desiredAccuracy: BMFDesiredAccuracy.best,
// rgc数据
isNeedNewVersionRgc: false,
//
pausesLocationUpdatesAutomatically: false,
// ,
//
allowsBackgroundLocationUpdates: false,
//
distanceFilter: 10,
);
return options;
}
class Location { class Location {
static Location _instance; static Location _instance;
@ -23,37 +76,27 @@ class Location {
LocationFlutterPlugin aMapFlutterLocation; LocationFlutterPlugin aMapFlutterLocation;
prepareLoc() { Future<bool> startLocation(context, Function(BaiduLocation result) locationCallback) async {
aMapFlutterLocation.prepareLoc({ aMapFlutterLocation.prepareLoc(initAndroidOptions().getMap(), initIOSOptions().getMap());
"coorType": "bd09ll",
"isNeedAddres": false,
"isNeedAltitude": false,
"isNeedLocationPoiList": false,
"isNeedLocationDescribe": false,
"isNeedNewVersionRgc": false,
"scanspan": 0,
"openGps": true,
"locationMode": 2,
}, {
"locationMode": "kCLLocationAccuracyBest",
"locationTimeout": 10,
"reGeocodeTimeout": 10,
"activityType": "CLActivityTypeAutomotiveNavigation",
"BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL",
"isNeedNewVersionRgc": false,
});
}
Future<bool> startLocation(context) async {
if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) { if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) {
enableLocation(context); enableLocation(context);
return false; return false;
} }
if (await Permission.location.isPermanentlyDenied) { if (await Permission.location.isPermanentlyDenied) {
requestDialog(context); requestDialog(context, locationCallback);
return false; return false;
} else if (await Permission.location.isGranted) { } else if (await Permission.location.isGranted) {
aMapFlutterLocation.startLocation(); aMapFlutterLocation.singleLocationCallback(callback: (BaiduLocation result) {
locationCallback.call(result);
});
if (Platform.isIOS) {
await aMapFlutterLocation.singleLocation({
'isReGeocode': true,
'isNetworkState': true,
});
} else if (Platform.isAndroid) {
await aMapFlutterLocation.startLocation();
}
return true; return true;
} else if (await Permission.location.isUndetermined) { } else if (await Permission.location.isUndetermined) {
await Permission.location.request(); await Permission.location.request();
@ -61,7 +104,7 @@ class Location {
} else { } else {
if (Platform.isIOS) { if (Platform.isIOS) {
// //
requestDialog(context); requestDialog(context, locationCallback);
} else { } else {
await Permission.location.request(); await Permission.location.request();
} }
@ -97,7 +140,7 @@ class Location {
); );
} }
requestDialog(context) { requestDialog(context, Function(BaiduLocation result) locationCallback) {
showCupertinoDialog( showCupertinoDialog(
context: context, context: context,
builder: (context) { builder: (context) {
@ -110,7 +153,7 @@ class Location {
if (result) { if (result) {
await openAppSettings(); await openAppSettings();
if (await Permission.location.isGranted) { if (await Permission.location.isGranted) {
startLocation(context); startLocation(context, locationCallback);
} }
} }
}, },

33
pubspec.lock

@ -92,20 +92,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.16.0" version: "1.16.0"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.1"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.5"
csslib: csslib:
dependency: transitive dependency: transitive
description: description:
@ -173,35 +159,35 @@ packages:
name: flutter_baidu_mapapi_base name: flutter_baidu_mapapi_base
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.1" version: "3.2.0"
flutter_baidu_mapapi_map: flutter_baidu_mapapi_map:
dependency: "direct main" dependency: "direct main"
description: description:
name: flutter_baidu_mapapi_map name: flutter_baidu_mapapi_map
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.1" version: "3.2.1"
flutter_baidu_mapapi_search: flutter_baidu_mapapi_search:
dependency: "direct main" dependency: "direct main"
description: description:
name: flutter_baidu_mapapi_search name: flutter_baidu_mapapi_search
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.1" version: "3.2.0"
flutter_baidu_mapapi_utils: flutter_baidu_mapapi_utils:
dependency: "direct main" dependency: "direct main"
description: description:
name: flutter_baidu_mapapi_utils name: flutter_baidu_mapapi_utils
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.1" version: "3.2.0"
flutter_bmflocation: flutter_bmflocation:
dependency: "direct main" dependency: "direct main"
description: description:
name: flutter_bmflocation name: flutter_bmflocation
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.4" version: "3.2.1"
flutter_easyloading: flutter_easyloading:
dependency: "direct main" dependency: "direct main"
description: description:
@ -248,7 +234,7 @@ packages:
name: flutter_plugin_android_lifecycle name: flutter_plugin_android_lifecycle
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.11" version: "2.0.7"
flutter_screenutil: flutter_screenutil:
dependency: "direct main" dependency: "direct main"
description: description:
@ -819,13 +805,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.0.1+3" version: "0.0.1+3"
uuid:
dependency: transitive
description:
name: uuid
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.2"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:

10
pubspec.yaml

@ -37,11 +37,11 @@ dependencies:
permission_handler: ^5.0.1+1 permission_handler: ^5.0.1+1
flutter_bmflocation: ^1.0.3 flutter_bmflocation: ^3.2.1
flutter_baidu_mapapi_base: ^2.0.1 flutter_baidu_mapapi_base: ^3.2.0
flutter_baidu_mapapi_map: ^2.0.1 flutter_baidu_mapapi_map: ^3.2.1
flutter_baidu_mapapi_search: ^2.0.1 flutter_baidu_mapapi_search: ^3.2.0
flutter_baidu_mapapi_utils: ^2.0.1 flutter_baidu_mapapi_utils: ^3.2.0
dio: ^3.0.10 dio: ^3.0.10
rxdart: ^0.26.0 rxdart: ^0.26.0

Loading…
Cancel
Save