From 8f0f2b10dc7e8056b6545b44b6c719bb254c717c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerard=20Mons=C3=B3?= Date: Wed, 24 Jul 2024 19:39:49 +0200 Subject: [PATCH] integrate map with country nasa page --- lib/screens/nasa_screen.dart | 60 +++++++++++++++++-- macos/Flutter/GeneratedPluginRegistrant.swift | 4 ++ pubspec.yaml | 2 +- .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 5 files changed, 65 insertions(+), 5 deletions(-) diff --git a/lib/screens/nasa_screen.dart b/lib/screens/nasa_screen.dart index cd7d654..776fa02 100644 --- a/lib/screens/nasa_screen.dart +++ b/lib/screens/nasa_screen.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:geocode/geocode.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:wildfiretracker/utils/body.dart'; @@ -41,6 +42,8 @@ class _NasaApiPageState extends State { // bool _loadingSatelliteData = false; final ValueNotifier _loadingSatelliteData = ValueNotifier(false); + GoogleMapController? _mapsController; + LGService get _lgService => GetIt.I(); NASAService get _nasaService => GetIt.I(); @@ -205,13 +208,15 @@ class _NasaApiPageState extends State { showBallon: true); }, onMaps: (satelliteData) async { - String googleMapsUrl = + /*String googleMapsUrl = "https://www.google.com/maps/search/?api=1&query=${satelliteData.latitude},${satelliteData.longitude}"; if (!await launchUrlString( googleMapsUrl)) { showSnackbar(context, "Could not open the map."); - } + }*/ + + }, ), )); @@ -229,11 +234,14 @@ class _NasaApiPageState extends State { borderRadius: BorderRadius.circular(12), // Same as the outer container child: GoogleMap( initialCameraPosition: const CameraPosition( - target: LatLng(37.7749, -122.4194), // replace with your initial coordinates + target: LatLng(10.7749, -122.4194), // replace with your initial coordinates zoom: 0.0, ), + onMapCreated: (GoogleMapController controller) { - // handle map created + setState(() { + _mapsController = controller; + }); }, ), ), @@ -260,7 +268,46 @@ class _NasaApiPageState extends State { }); } + Future _goToLatLang(double lat, double lng) async { + // wait 1 second + await Future.delayed(const Duration(seconds: 3)); + + CameraPosition position = CameraPosition( + bearing: 192.8334901395799, + target: LatLng(lat, lng), + zoom: 5.0, + tilt: 59.440717697143555, + ); + setState(() { + _mapsController?.animateCamera(CameraUpdate.newCameraPosition(position)); + }); + } + + Future _goToCountry(String countryName) async { + // wait 1 second + //await Future.delayed(Duration(seconds: 5)); + Coordinates cords = await GeoCode().forwardGeocoding(address: _selectedCountry.name); + CameraPosition _kLake = CameraPosition( + bearing: 192.8334901395799, + target: LatLng(37.43296265331129, -122.08832357078792), + tilt: 59.440717697143555, + zoom: 9.151926040649414); + CameraPosition position = CameraPosition( + bearing: 192.8334901395799, + target: LatLng(cords.latitude ?? 40.712776, cords.longitude ?? -74.005974), + zoom: 6.0, + tilt: 59.440717697143555, + ); + //final GoogleMapController controller = await _mapsController.future; + setState(() { + _mapsController?.animateCamera(CameraUpdate.newCameraPosition(position)); + }); + } + void getLiveFireByCountry() { + //_goToLatLang(33.89589, 62.97857); + //return; + setState(() { _loadingSatelliteData.value = true; }); @@ -273,6 +320,11 @@ class _NasaApiPageState extends State { }); SatelliteData.setPlacemarkFromCoordinates( satelliteData, _loadingSatelliteData, refreshState); + //_goToCountry(_selectedCountry.name); + if (_satelliteData.isNotEmpty) { + _goToLatLang(_satelliteData[0].latitude, _satelliteData[0].longitude); + } + }).onError((error, stackTrace) { _satelliteData = []; setState(() { diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index b19945c..1c77e06 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,11 +5,15 @@ import FlutterMacOS import Foundation +import geolocator_apple +import location import path_provider_foundation import shared_preferences_foundation import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) + LocationPlugin.register(with: registry.registrar(forPlugin: "LocationPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) diff --git a/pubspec.yaml b/pubspec.yaml index 7eef77a..ca0150c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+2 +version: 1.0.0+3 environment: sdk: '>=3.1.5 <4.0.0' diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 4f78848..94586cc 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,12 @@ #include "generated_plugin_registrant.h" +#include #include void RegisterPlugins(flutter::PluginRegistry* registry) { + GeolocatorWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("GeolocatorWindows")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 88b22e5..f0bcafd 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + geolocator_windows url_launcher_windows )