use structs to draw custom map pointers
This commit is contained in:
@@ -66,7 +66,7 @@ class _LandmarkCardState extends State<LandmarkCard> {
|
||||
// alignment: Alignment.topRight,
|
||||
// child: Icon(Icons.push_pin, color: theme.primaryColor),
|
||||
// ),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import 'package:fast_network_navigation/structs/landmark.dart';
|
||||
import 'package:fast_network_navigation/utils/get_landmarks.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
|
||||
@@ -10,33 +11,36 @@ class MapWidget extends StatefulWidget {
|
||||
class _MapWidgetState extends State<MapWidget> {
|
||||
late GoogleMapController mapController;
|
||||
// coordinates of Paris
|
||||
final LatLng _center = const LatLng(48.8566, 2.3522);
|
||||
CameraPosition _cameraPosition = CameraPosition(
|
||||
target: LatLng(48.8566, 2.3522),
|
||||
zoom: 11.0,
|
||||
);
|
||||
Set<Marker> markers = <Marker>{};
|
||||
|
||||
|
||||
void _onMapCreated(GoogleMapController controller) {
|
||||
mapController = controller;
|
||||
addLandmarks();
|
||||
drawLandmarks();
|
||||
}
|
||||
|
||||
|
||||
void _onCameraIdle() {
|
||||
// print(mapController.getLatLng());
|
||||
// print(mapController.getLatLng(ScreenCoordinate(x: 0, y: 0)));
|
||||
}
|
||||
|
||||
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),
|
||||
// ));
|
||||
// }
|
||||
void drawLandmarks() async {
|
||||
// (re)draws landmarks on the map
|
||||
List<Landmark> landmarks = await fetchLandmarks();
|
||||
setState(() {
|
||||
for (Landmark landmark in landmarks) {
|
||||
markers.add(Marker(
|
||||
markerId: MarkerId(landmark.name),
|
||||
position: LatLng(landmark.location[0], landmark.location[1]),
|
||||
infoWindow: InfoWindow(title: landmark.name, snippet: landmark.type.name),
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -44,61 +48,11 @@ class _MapWidgetState extends State<MapWidget> {
|
||||
Widget build(BuildContext context) {
|
||||
return GoogleMap(
|
||||
onMapCreated: _onMapCreated,
|
||||
initialCameraPosition: CameraPosition(
|
||||
target: _center,
|
||||
zoom: 11.0,
|
||||
),
|
||||
initialCameraPosition: _cameraPosition,
|
||||
onCameraIdle: _onCameraIdle,
|
||||
// onLongPress: ,
|
||||
// markers: #,
|
||||
markers: 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();});
|
||||
// }
|
||||
// }
|
||||
|
||||
|
Reference in New Issue
Block a user