Skip to content

Commit

Permalink
integrate map with country nasa page
Browse files Browse the repository at this point in the history
  • Loading branch information
gmonso committed Jul 24, 2024
1 parent a567e78 commit 8f0f2b1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
60 changes: 56 additions & 4 deletions lib/screens/nasa_screen.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -41,6 +42,8 @@ class _NasaApiPageState extends State<NasaApiPage> {
// bool _loadingSatelliteData = false;
final ValueNotifier<bool> _loadingSatelliteData = ValueNotifier<bool>(false);

GoogleMapController? _mapsController;

LGService get _lgService => GetIt.I<LGService>();

NASAService get _nasaService => GetIt.I<NASAService>();
Expand Down Expand Up @@ -205,13 +208,15 @@ class _NasaApiPageState extends State<NasaApiPage> {
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.");
}
}*/


},
),
));
Expand All @@ -229,11 +234,14 @@ class _NasaApiPageState extends State<NasaApiPage> {
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;
});
},
),
),
Expand All @@ -260,7 +268,46 @@ class _NasaApiPageState extends State<NasaApiPage> {
});
}

Future<void> _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<void> _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;
});
Expand All @@ -273,6 +320,11 @@ class _NasaApiPageState extends State<NasaApiPage> {
});
SatelliteData.setPlacemarkFromCoordinates(
satelliteData, _loadingSatelliteData, refreshState);
//_goToCountry(_selectedCountry.name);
if (_satelliteData.isNotEmpty) {
_goToLatLang(_satelliteData[0].latitude, _satelliteData[0].longitude);
}

}).onError((error, stackTrace) {
_satelliteData = [];
setState(() {
Expand Down
4 changes: 4 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include "generated_plugin_registrant.h"

#include <geolocator_windows/geolocator_windows.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
GeolocatorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("GeolocatorWindows"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
geolocator_windows
url_launcher_windows
)

Expand Down

0 comments on commit 8f0f2b1

Please sign in to comment.