104 lines
3.3 KiB
Dart
104 lines
3.3 KiB
Dart
import 'package:fast_network_navigation/structs/landmark.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
class MapWidget extends StatefulWidget {
|
|
@override
|
|
State<MapWidget> createState() => _MapWidgetState();
|
|
}
|
|
|
|
class _MapWidgetState extends State<MapWidget> {
|
|
late GoogleMapController mapController;
|
|
// coordinates of Paris
|
|
final LatLng _center = const LatLng(48.8566, 2.3522);
|
|
|
|
void _onMapCreated(GoogleMapController controller) {
|
|
mapController = controller;
|
|
addLandmarks();
|
|
}
|
|
void _onCameraIdle() {
|
|
// print(mapController.getLatLng());
|
|
}
|
|
|
|
void addLandmarks() {
|
|
// // adds a marker for each landmark
|
|
// List<Landmark> landmarks = [
|
|
// Landmark(name: "Eiffel Tower", location: [48.8584, 2.2945], type: LandmarkType(name: "Type 1")),
|
|
// Landmark(name: "Louvre Museum", location: [48.8606, 2.3376], type: LandmarkType(name: "Type 1")),
|
|
// Landmark(name: "Notre-Dame Cathedral", location: [48.8529, 2.3499], type: LandmarkType(name: "Type 1")),
|
|
// Landmark(name: "Arc de Triomphe", location: [48.8738, 2.2950], type: LandmarkType(name: "Type 1")),
|
|
// Landmark(name: "Palace of Versailles", location: [48.8014, 2.1301], type: LandmarkType(name: "Type 1")),
|
|
// ];
|
|
|
|
// for (Landmark landmark in landmarks) {
|
|
// mapController.
|
|
// mapController.addMarker(MarkerOptions(
|
|
// position: LatLng(landmark.location[0], landmark.location[1]),
|
|
// infoWindowText: InfoWindowText(landmark.name, landmark.type.name),
|
|
// ));
|
|
// }
|
|
}
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GoogleMap(
|
|
onMapCreated: _onMapCreated,
|
|
initialCameraPosition: CameraPosition(
|
|
target: _center,
|
|
zoom: 11.0,
|
|
),
|
|
onCameraIdle: _onCameraIdle,
|
|
// onLongPress: ,
|
|
// markers: #,
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GeoCode geoCode = GeoCode();
|
|
// String _currentCityName = "...";
|
|
// final Debounce _debounce = Debounce(Duration(seconds: 3));
|
|
|
|
// final LatLng _center = const LatLng(45.521563, -122.677433);
|
|
// late GoogleMapController mapController;
|
|
|
|
// void _onMapCreated(GoogleMapController controller) {
|
|
// mapController = controller;
|
|
// }
|
|
|
|
// // void _setCurrentCityName() async {
|
|
// if (mapController.camera.zoom < 9) {
|
|
// return; // Don't bother if the view is too wide
|
|
// }
|
|
// var currentCoordinates = mapController.camera.center;
|
|
// String? city;
|
|
|
|
// try{
|
|
// List<Placemark> placemarks = await placemarkFromCoordinates(currentCoordinates.latitude, currentCoordinates.longitude);
|
|
// city = placemarks[0].locality.toString();
|
|
// } catch (e) {
|
|
// debugPrint("Error: $e");
|
|
// try {
|
|
// Address address = await geoCode.reverseGeocoding(latitude: currentCoordinates.latitude, longitude: currentCoordinates.longitude);
|
|
|
|
// if (address.city == null || address.city.toString().contains("Throttled!")){
|
|
// throw Exception("Probably rate limited");
|
|
// }
|
|
// city = address.city.toString();
|
|
// } catch (e) {
|
|
// debugPrint("Error: $e");
|
|
|
|
// }
|
|
// }
|
|
// if (city != null) {
|
|
// setState(() {
|
|
// _currentCityName = city!;
|
|
// });
|
|
// } else {
|
|
// _debounce(() async {_setCurrentCityName();});
|
|
// }
|
|
// }
|
|
|
|
|