adding google maps baby!
This commit is contained in:
81
frontend/lib/modules/map.dart
Normal file
81
frontend/lib/modules/map.dart
Normal file
@@ -0,0 +1,81 @@
|
||||
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();});
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user