itnerary
This commit is contained in:
@@ -23,30 +23,47 @@ class CurrentLocationSelection extends StatefulWidget {
|
||||
class _CurrentLocationSelectionState extends State<CurrentLocationSelection> {
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
LatLng? _currentLatLng;
|
||||
bool loading = false;
|
||||
|
||||
Future<void> _getCurrentLocation() async {
|
||||
LocationPermission permission = await Geolocator.requestPermission();
|
||||
try {
|
||||
setState(() {
|
||||
loading = true;
|
||||
});
|
||||
LocationPermission permission = await Geolocator.requestPermission();
|
||||
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Location permission denied')),
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Location permission denied')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.high,
|
||||
);
|
||||
return;
|
||||
|
||||
final lat = position.latitude;
|
||||
final lng = position.longitude;
|
||||
|
||||
setState(() {
|
||||
_currentLatLng = LatLng(lat, lng);
|
||||
});
|
||||
|
||||
await _getAddressFromLatLng(lat, lng);
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
} finally {
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.high,
|
||||
);
|
||||
|
||||
final lat = position.latitude;
|
||||
final lng = position.longitude;
|
||||
|
||||
setState(() {
|
||||
_currentLatLng = LatLng(lat, lng);
|
||||
});
|
||||
|
||||
await _getAddressFromLatLng(lat, lng);
|
||||
}
|
||||
|
||||
Future<void> _getAddressFromLatLng(double lat, double lng) async {
|
||||
@@ -57,7 +74,6 @@ class _CurrentLocationSelectionState extends State<CurrentLocationSelection> {
|
||||
final place = placemarks.first;
|
||||
|
||||
final address = [
|
||||
place.name,
|
||||
place.street,
|
||||
place.subLocality,
|
||||
place.locality,
|
||||
@@ -133,34 +149,41 @@ class _CurrentLocationSelectionState extends State<CurrentLocationSelection> {
|
||||
child: SizedBox(
|
||||
height: 250.h,
|
||||
width: double.infinity,
|
||||
child: FlutterMap(
|
||||
options: MapOptions(
|
||||
initialCenter: _currentLatLng!,
|
||||
initialZoom: 15,
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate:
|
||||
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
subdomains: const ['a', 'b', 'c'],
|
||||
userAgentPackageName: 'com.citycards.customer',
|
||||
),
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
Marker(
|
||||
point: _currentLatLng!,
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: const Icon(
|
||||
Icons.location_pin,
|
||||
color: Colors.red,
|
||||
size: 40,
|
||||
),
|
||||
child: loading == true
|
||||
? Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Color(0xFFF95F62),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: FlutterMap(
|
||||
options: MapOptions(
|
||||
initialCenter: _currentLatLng!,
|
||||
initialZoom: 15,
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate:
|
||||
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
subdomains: const ['a', 'b', 'c'],
|
||||
userAgentPackageName:
|
||||
'com.citycards.customer',
|
||||
),
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
Marker(
|
||||
point: _currentLatLng!,
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: const Icon(
|
||||
Icons.location_pin,
|
||||
color: Colors.red,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: GestureDetector(
|
||||
|
||||
Reference in New Issue
Block a user