0
0
Fluttermobile~10 mins

Location and GPS in Flutter - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Flutter package that provides location services.

Flutter
import '[1]';
Drag options to blanks, or click blank then click option'
Apackage:flutter/widgets.dart
Bpackage:flutter/material.dart
Cpackage:location/location.dart
Dpackage:flutter/services.dart
Attempts:
3 left
💡 Hint
Common Mistakes
Importing material.dart instead of location.dart
Using widgets.dart which does not provide location features
2fill in blank
medium

Complete the code to create a Location instance to access GPS data.

Flutter
final location = [1]();
Drag options to blanks, or click blank then click option'
ALocationManager
BLocation
CGeoLocator
DGPSService
Attempts:
3 left
💡 Hint
Common Mistakes
Using classes not defined in the location package
Trying to instantiate a service class that does not exist
3fill in blank
hard

Fix the error in the code to request permission to access location.

Flutter
bool _serviceEnabled = await location.[1]();
Drag options to blanks, or click blank then click option'
ArequestLocationPermission
BrequestPermission
CcheckPermission
DrequestService
Attempts:
3 left
💡 Hint
Common Mistakes
Using requestPermission() which asks for permission but not service status
Using checkPermission() which only checks permission status
4fill in blank
hard

Fill both blanks to get the current location coordinates asynchronously.

Flutter
LocationData currentLocation = await location.[1]();
double latitude = currentLocation.[2];
Drag options to blanks, or click blank then click option'
AgetLocation
Blatitude
CgetCurrentPosition
Dlongitude
Attempts:
3 left
💡 Hint
Common Mistakes
Using getCurrentPosition() which is from a different package
Accessing longitude instead of latitude for latitude value
5fill in blank
hard

Fill all three blanks to listen for location changes and update UI accordingly.

Flutter
location.[1].listen((LocationData currentLocation) {
  setState(() {
    _latitude = currentLocation.[2];
    _longitude = currentLocation.[3];
  });
});
Drag options to blanks, or click blank then click option'
AonLocationChanged
Blatitude
Clongitude
DgetLocation
Attempts:
3 left
💡 Hint
Common Mistakes
Using getLocation instead of onLocationChanged for continuous updates
Mixing up latitude and longitude properties