我已经提到了其他堆栈溢出问题,但似乎找不到适用于我的解决方案。我试图显示动态的谷歌地图,但是即使我已授予许可权,fetlocation()方法也返回null,而且在consol中也没有看到我要打印的代码。 这是代码:
Future<bool> assignService(Location loc) async {
bool servicestatus = await loc.serviceEnabled();
print("Service status $servicestatus");
return servicestatus;
}
Future<PermissionStatus> assignPermission(Location loc) async {
var hasPermission = await loc.hasPermission();
print("Permission status $hasPermission");
return hasPermission;
}
Location location = Location();
var _serviceEnabled;
var _serve = assignService(location).then((value) => _serviceEnabled = value);
//var _permissionGranted = assignPermission(location);
var _permissionGranted;
var _permi = assignPermission(location).then((value) => _permissionGranted = value);
void startService(){
if (!_serviceEnabled) {
_serviceEnabled = assignService(location);
print("service disabled");
if (!_serviceEnabled) {
return;
}
}
if (_permissionGranted == PermissionStatus.denied){
_permissionGranted = assignPermission(location);
print("permission denied");
if (_permissionGranted != PermissionStatus.granted) {
return;
}
}
}
var map;
final mapp = location.getLocation().then((value) => map = value);
class NearbyScreen extends StatelessWidget {
@override
//LocationHelper.mapviewpointer(latitude: )
Widget build(BuildContext context) {
return /* !_serviceEnabled ? Center(child:Text("Page cannot be viewed"),) :*/
map == null
? Center(
child: Text("Null response"),
)
: GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(map.latitude, map.longitude
/* double.parse(coordinates[0]), double.parse(coordinates[1]) */)),
minMaxZoomPreference: MinMaxZoomPreference(10, 20),
zoomControlsEnabled: true,
);
}
}