Remy Moll 3854cef54a
Some checks failed
Test code / Test code (push) Failing after 24s
Build web / Build Web (pull_request) Failing after 3m10s
Test code / Test code (pull_request) Failing after 44s
Build and release APK / Build APK (pull_request) Failing after 15m48s
adding google maps baby!
2024-05-17 20:12:59 +02:00

81 lines
2.2 KiB
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;
final LatLng _center = const LatLng(45.521563, -122.677433);
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
void _onCameraIdle() {
// print(mapController.getLatLng());
}
@override
Widget build(BuildContext context) {
return GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
onCameraIdle: _onCameraIdle,
);
}
}
// 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();});
// }
// }