final with gas Stations and navigation to then
This commit is contained in:
76
lib/pages/gaslist/widgets/map_view.dart
Normal file
76
lib/pages/gaslist/widgets/map_view.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
// map_dialog_view.dart
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class MapDialogView extends StatelessWidget {
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
|
||||
const MapDialogView({
|
||||
super.key,
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
});
|
||||
|
||||
// Funktion zum Öffnen der Karten-URL
|
||||
void _openMap() async {
|
||||
String url = '';
|
||||
final coords = '$latitude,$longitude';
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
// Android: Startet die Google Maps Navigation
|
||||
url =
|
||||
'https://www.google.com/maps/dir/?api=1&destination=$coords'; // mode=d für Fahren
|
||||
} else if (Platform.isIOS) {
|
||||
// iOS: Startet die Apple Maps Navigation
|
||||
url =
|
||||
'https://maps.apple.com/?daddr=$coords&dirflg=d'; // daddr für destination, dirflg=d für driving
|
||||
} else {
|
||||
// Fallback-URL für die Google Maps Website mit Wegbeschreibung
|
||||
url = 'https://www.google.com/maps/dir/?api=1&destination=$coords';
|
||||
}
|
||||
// Hier die URL-Logik einfügen, die Sie bereits kennen
|
||||
//final url = 'http://googleusercontent.com/maps.google.com/8';
|
||||
final uri = Uri.parse(url);
|
||||
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri);
|
||||
} else {
|
||||
// Eine Snackbar oder ein Dialog, um den Fehler zu melden
|
||||
print('Fehler: Konnte Karten-App nicht öffnen.');
|
||||
}
|
||||
Get.back();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Karte öffnen'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start, // Passt die Höhe an den Inhalt an
|
||||
children: [
|
||||
Text('Koordinaten'),
|
||||
Text('Latitude: $latitude'),
|
||||
Text('Longitude: $longitude'),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: _openMap, // Ruft die Methode zum Öffnen der Karte auf
|
||||
child: const Text('Karten-App öffnen'),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(), // Schließt den Dialog
|
||||
child: const Text('Schließen'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user