add messae error
This commit is contained in:
parent
f880ac1002
commit
4a04520800
@ -50,14 +50,14 @@ class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
|
||||
double longitude = 0.0;
|
||||
double latitude = 0.0;
|
||||
bool isLoading = true;
|
||||
LatLng? userPosition;
|
||||
late LatLng userPosition;
|
||||
bool isUserPositionInitialized = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initToken();
|
||||
_getEventInfo();
|
||||
_getUserLocation();
|
||||
}
|
||||
|
||||
void _initToken() {
|
||||
@ -80,6 +80,7 @@ class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
|
||||
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
||||
latitude = events["latitude"];
|
||||
longitude = events["longitude"];
|
||||
_getUserLocation();
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
@ -151,6 +152,7 @@ class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
|
||||
);
|
||||
setState(() {
|
||||
userPosition = LatLng(position.latitude, position.longitude);
|
||||
isUserPositionInitialized = true;
|
||||
});
|
||||
} catch (e) {
|
||||
showErrorDialog(context, "Failed to get user location: $e");
|
||||
@ -193,11 +195,11 @@ class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
|
||||
final userMarkerImage = await _loadMarkerImage('images/marker.png');
|
||||
|
||||
// Register the image with Mapbox
|
||||
await mapController.addImage('user-marker', userMarkerImage);
|
||||
await mapController.addImage('event-marker', userMarkerImage);
|
||||
|
||||
final symbolOptions = SymbolOptions(
|
||||
geometry: LatLng(latitude, longitude),
|
||||
iconImage: "user-marker", // Use the registered custom marker
|
||||
iconImage: "event-marker", // Use the registered custom marker
|
||||
iconSize: 0.4, // Optional: Adjust size
|
||||
);
|
||||
|
||||
@ -220,6 +222,12 @@ class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
|
||||
}
|
||||
|
||||
Future<void> _drawRouteAndMarkers() async {
|
||||
if (!isUserPositionInitialized) {
|
||||
showErrorDialog(
|
||||
context, "User position is not yet initialized. Try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mapController != null &&
|
||||
userPosition != null &&
|
||||
latitude != 0.0 &&
|
||||
@ -232,10 +240,10 @@ class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
|
||||
final userMarkerImage = await _loadMarkerImage('images/marker.png');
|
||||
|
||||
// Register the image with Mapbox
|
||||
await mapController.addImage('event-marker', userMarkerImage);
|
||||
await mapController.addImage('user-marker', userMarkerImage);
|
||||
await mapController.addSymbol(SymbolOptions(
|
||||
geometry: destination,
|
||||
iconImage: 'event-marker', // Custom icon for event
|
||||
geometry: userPosition,
|
||||
iconImage: 'user-marker', // Custom icon for event
|
||||
iconSize: 0.4,
|
||||
));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user