initLocation method
Function to get current locations if permission available, otherwise set default location
Implementation
Future<void> initLocation() async {
_onInitCamera = true;
try {
Position currentPos;
try {
final serviceEnable = await Geolocator.isLocationServiceEnabled();
if (serviceEnable) {
var permission = await Geolocator.checkPermission();
if ((permission != LocationPermission.always || permission != LocationPermission.whileInUse)) {
permission = await Geolocator.requestPermission();
}
currentPos = await Geolocator.getCurrentPosition();
} else {
currentPos = Position(
latitude: Platform.isAndroid ? 0 : -6.215412,
longitude: Platform.isAndroid ? 0 : 106.777773,
timestamp: DateTime.now(), accuracy: 0, altitude: 0, heading: 0, speed: 0, speedAccuracy: 0
);
}
} catch(_) {
currentPos = Position(
latitude: Platform.isAndroid ? 0 : -6.215412,
longitude: Platform.isAndroid ? 0 : 106.777773,
timestamp: DateTime.now(), accuracy: 0, altitude: 0, heading: 0, speed: 0, speedAccuracy: 0
);
}
_sourceLocation = LatLng(currentPos.latitude, currentPos.longitude);
_onInitCamera = false;
} catch (e) {
print(e.toString());
initLocation();
}
notifyListeners();
}