You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.4 KiB
127 lines
3.4 KiB
|
|
|
|
|
|
import 'dart:io'; |
|
|
|
import 'package:android_intent_plus/android_intent.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/view_widget/request_permission.dart'; |
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
|
class Location { |
|
|
|
static late Location _instance; |
|
|
|
Location._internal() { |
|
aMapFlutterLocation = LocationFlutterPlugin(); |
|
} |
|
|
|
static Location getInstance() { |
|
if (_instance == null) { |
|
_instance = Location._internal(); |
|
} |
|
return _instance; |
|
} |
|
|
|
late LocationFlutterPlugin aMapFlutterLocation; |
|
|
|
prepareLoc() { |
|
aMapFlutterLocation.prepareLoc({ |
|
"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<void> startLocation(context) async { |
|
if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) { |
|
enableLocation(context); |
|
return; |
|
} |
|
if (await Permission.location.isPermanentlyDenied) { |
|
requestDialog(context); |
|
} else if (await Permission.location.isGranted) { |
|
aMapFlutterLocation.startLocation(); |
|
} else if (await Permission.location.isUndetermined) { |
|
await Permission.location.request(); |
|
} else { |
|
if (Platform.isIOS) { |
|
//去设置中心 |
|
requestDialog(context); |
|
} else { |
|
await Permission.location.request(); |
|
} |
|
} |
|
} |
|
|
|
void stopLocation() { |
|
aMapFlutterLocation.stopLocation(); |
|
} |
|
|
|
enableLocation(context) { |
|
showCupertinoDialog( |
|
context: context, |
|
builder: (context) { |
|
return RequestPermission( |
|
"assets/image/icon_permission_location_bg.png", |
|
S.of(context).nindingweigongnengweikaiqi, |
|
S.of(context).weilexiangnintuijianfujindemendianxinxi, |
|
S.of(context).dakaidingwei, |
|
(result) async { |
|
if (result) { |
|
final AndroidIntent intent = AndroidIntent( |
|
action: 'action_location_source_settings', |
|
package: "com.zsw.huixiang"); |
|
await intent.launch(); |
|
// startLocation(); |
|
} |
|
}, |
|
heightRatioWithWidth: 0.82, |
|
); |
|
}, |
|
); |
|
} |
|
|
|
requestDialog(context) { |
|
showCupertinoDialog( |
|
context: context, |
|
builder: (context) { |
|
return RequestPermission( |
|
"assets/image/icon_permission_location_bg.png", |
|
S.of(context).nindingweiquanxianweiyunxu, |
|
S.of(context).weilexiangnintuijianfujindemendianxinxi, |
|
S.of(context).kaiqiquanxian, |
|
(result) async { |
|
if (result) { |
|
await openAppSettings(); |
|
if (await Permission.location.isGranted) { |
|
startLocation(context); |
|
} |
|
} |
|
}, |
|
heightRatioWithWidth: 0.82, |
|
); |
|
}); |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|