adding google maps baby!
This commit is contained in:
parent
3f1c16b575
commit
3854cef54a
@ -35,7 +35,7 @@ jobs:
|
||||
- run: flutter pub get
|
||||
working-directory: ./frontend
|
||||
|
||||
- run: flutter build apk --debug --split-per-abi
|
||||
- run: flutter build apk --release --split-per-abi
|
||||
working-directory: ./frontend
|
||||
|
||||
|
||||
|
@ -45,6 +45,9 @@ android {
|
||||
applicationId "com.example.fast_network_navigation"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||
// Minimum Android version for Google Maps SDK
|
||||
// https://developers.google.com/maps/flutter-package/config#android
|
||||
minSdk = 21
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
targetSdkVersion flutter.targetSdkVersion
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
|
@ -28,7 +28,9 @@
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
android:value="2"
|
||||
android:name="com.google.android.geo.API_KEY"
|
||||
android:value="AIzaSyCeWk_D2xvfOHLidvV56EZeQCUybypEntw"/> />
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility?hl=en and
|
||||
|
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();});
|
||||
// }
|
||||
// }
|
||||
|
||||
|
@ -1,17 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:sliding_up_panel/sliding_up_panel.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
import 'package:geocode/geocode.dart';
|
||||
import 'dart:async';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
|
||||
import 'package:fast_network_navigation/modules/navigation.dart';
|
||||
import 'package:fast_network_navigation/modules/map.dart';
|
||||
|
||||
class MapPage extends StatefulWidget {
|
||||
|
||||
|
||||
class MainPage extends StatefulWidget {
|
||||
@override
|
||||
_MapPageState createState() => _MapPageState();
|
||||
State<MainPage> createState() => _MainPageState();
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Debounce {
|
||||
Duration delay;
|
||||
Timer? _timer;
|
||||
@ -31,44 +35,7 @@ class Debounce {
|
||||
}
|
||||
|
||||
|
||||
class _MapPageState extends State<MapPage> {
|
||||
GeoCode geoCode = GeoCode();
|
||||
final mapController = MapController();
|
||||
String _currentCityName = "...";
|
||||
final Debounce _debounce = Debounce(Duration(seconds: 3));
|
||||
|
||||
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();});
|
||||
}
|
||||
}
|
||||
class _MainPageState extends State<MainPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -77,21 +44,7 @@ class _MapPageState extends State<MapPage> {
|
||||
renderPanelSheet: false,
|
||||
panel: _floatingPanel(theme),
|
||||
collapsed: _floatingCollapsed(theme),
|
||||
body: FlutterMap(
|
||||
mapController: mapController,
|
||||
options: MapOptions(
|
||||
initialZoom: 11,
|
||||
initialCenter: LatLng(51.509364, -0.128928),
|
||||
onMapReady: () {
|
||||
mapController.mapEventStream.listen((evt) {_debounce(() async {_setCurrentCityName();});});
|
||||
// And any other `MapController` dependent non-movement methods
|
||||
},
|
||||
|
||||
),
|
||||
children: [
|
||||
openStreetMapTileLayer,
|
||||
],
|
||||
),
|
||||
body: MapWidget()
|
||||
);
|
||||
}
|
||||
|
||||
@ -138,16 +91,9 @@ class _MapPageState extends State<MapPage> {
|
||||
Widget Greeting (ThemeData theme) {
|
||||
return Center(
|
||||
child: Text(
|
||||
"Explore ${_currentCityName}",
|
||||
"Explore #todo",
|
||||
style: TextStyle(color: theme.primaryColor, fontSize: 24.0, fontWeight: FontWeight.bold),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TileLayer get openStreetMapTileLayer => TileLayer(
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'flutter_map',
|
||||
);
|
||||
|
||||
// Add a pin to the map
|
||||
|
@ -41,6 +41,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.18.0"
|
||||
csslib:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: csslib
|
||||
sha256: "706b5707578e0c1b4b7550f64078f0a0f19dec3f50a178ffae7006b0a9ca58fb"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -78,11 +86,24 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.0"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_plugin_android_lifecycle
|
||||
sha256: "8cf40eebf5dec866a6d1956ad7b4f7016e6c0cc69847ab946833b7d43743809f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.19"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
geocode:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -123,6 +144,62 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.0"
|
||||
google_maps:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_maps
|
||||
sha256: "47eef3836b49bb030d5cb3afc60b8451408bf34cf753e571b645d6529eb4251a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.1.0"
|
||||
google_maps_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: google_maps_flutter
|
||||
sha256: c1972cbad779bc5346c49045f26ae45550a0958b1cbca5b524dd3c8954995d28
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.6.1"
|
||||
google_maps_flutter_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_maps_flutter_android
|
||||
sha256: "0bcadb80eba39afda77dede89a6caafd3b68f2786b90491eceea4a01c3db181c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.8.0"
|
||||
google_maps_flutter_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_maps_flutter_ios
|
||||
sha256: e5132d17f051600d90d79d9f574b177c24231da702453a036db2490f9ced4646
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.6.0"
|
||||
google_maps_flutter_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_maps_flutter_platform_interface
|
||||
sha256: "167af879da4d004cd58771f1469b91dcc3b9b0a2c5334cc6bf71fd41d4b35403"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.6.0"
|
||||
google_maps_flutter_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_maps_flutter_web
|
||||
sha256: "0c0d5c723d94b295cf86dd1c45ff91d2ac1fff7c05ddca4f01bef9fa0a014690"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.7"
|
||||
html:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: html
|
||||
sha256: "3a7812d5bcd2894edf53dfaf8cd640876cf6cef50a8f238745c8b8120ea74d3a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.15.4"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -147,6 +224,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.19.0"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js
|
||||
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.7"
|
||||
js_wrapping:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js_wrapping
|
||||
sha256: e385980f7c76a8c1c9a560dfb623b890975841542471eade630b2871d243851c
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.4"
|
||||
latlong2:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -267,6 +360,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
sanitize_html:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sanitize_html
|
||||
sha256: "12669c4a913688a26555323fb9cec373d8f9fbe091f2d01c40c723b33caa8989"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@ -304,6 +405,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
stream_transform:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_transform
|
||||
sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -378,4 +487,4 @@ packages:
|
||||
version: "2.0.0"
|
||||
sdks:
|
||||
dart: ">=3.3.4 <4.0.0"
|
||||
flutter: ">=3.18.0-18.0.pre.54"
|
||||
flutter: ">=3.19.0"
|
||||
|
@ -40,6 +40,7 @@ dependencies:
|
||||
latlong2: ^0.9.1
|
||||
geocoding: ^3.0.0
|
||||
geocode: ^1.0.3
|
||||
google_maps_flutter: ^2.6.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
@ -14,6 +14,7 @@
|
||||
This is a placeholder for base href that will be replaced by the value of
|
||||
the `--base-href` argument provided to `flutter build`.
|
||||
-->
|
||||
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCeWk_D2xvfOHLidvV56EZeQCUybypEntw"></script>
|
||||
<base href="$FLUTTER_BASE_HREF">
|
||||
|
||||
<meta charset="UTF-8">
|
||||
|
Loading…
x
Reference in New Issue
Block a user