From 323aa21be12854c460d070219cee24a279d2afa5 Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Tue, 18 Mar 2025 17:00:55 -0300 Subject: [PATCH] =?UTF-8?q?Criado=20a=20p=C3=A1gina=20de=20exbi=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20mapa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tracker/src/screens/MapScreen.jsx | 52 ++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/Tracker/src/screens/MapScreen.jsx b/Tracker/src/screens/MapScreen.jsx index 9ba3122..1754697 100644 --- a/Tracker/src/screens/MapScreen.jsx +++ b/Tracker/src/screens/MapScreen.jsx @@ -1,12 +1,48 @@ -import { StyleSheet, Text, View } from 'react-native'; -import { StatusBar } from 'expo-status-bar'; +import React, { useEffect, useState } from 'react'; +import { View } from 'react-native'; +import MapView, { Polyline, Marker } from 'react-native-maps'; +import Storage from '../system/database/storage'; + +export default function MapScreen() { + const [coordinates, setCoordinates] = useState([]); + const storage = Storage.getInstance(); + + useEffect(() => { + const fetchCoordinates = async () => { + const data = await storage.listData(); + if (data) { + const parsedCoordinates = data.map(([_, value]) => JSON.parse(value)); + setCoordinates(parsedCoordinates); + } + }; + + // Buscar localização ao iniciar a tela + fetchCoordinates(); + + // Atualizar a cada 30 segundos para sincronizar com o App.js + const interval = setInterval(fetchCoordinates, 30000); + + return () => clearInterval(interval); // Cleanup ao desmontar o componente + }, []); -export default function MapScreen({navigation}){ return ( - - Open up App.js to start working on your app! - + + 0 ? coordinates[0].latitude : 37.78825, + longitude: coordinates.length > 0 ? coordinates[0].longitude : -122.4324, + latitudeDelta: 0.01, + longitudeDelta: 0.01, + }} + > + {coordinates.length > 0 && ( + <> + + + + )} + - ); - + ); } \ No newline at end of file