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.
 
 
 
 
 
 

132 lines
3.5 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 Location _instance;
Location._internal() {
aMapFlutterLocation = LocationFlutterPlugin();
}
static Location getInstance() {
if (_instance == null) {
_instance = Location._internal();
}
return _instance;
}
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<bool> startLocation(context) async {
if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) {
enableLocation(context);
return false;
}
if (await Permission.location.isPermanentlyDenied) {
requestDialog(context);
return false;
} else if (await Permission.location.isGranted) {
aMapFlutterLocation.startLocation();
return true;
} else if (await Permission.location.isUndetermined) {
await Permission.location.request();
return false;
} else {
if (Platform.isIOS) {
//去设置中心
requestDialog(context);
} else {
await Permission.location.request();
}
return false;
}
}
void stopLocation() {
if (aMapFlutterLocation != null)
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,
);
});
}
}