diff --git a/src/app/context/CurrentLocationContext.js b/src/app/context/CurrentLocationContext.js index bb95420..ec626da 100644 --- a/src/app/context/CurrentLocationContext.js +++ b/src/app/context/CurrentLocationContext.js @@ -38,7 +38,12 @@ const CurrentLocationProvider = ({ children }) => { Location.setGoogleApiKey("AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc"); const address = await Location.reverseGeocodeAsync(coordenadas); - setCurrentLocation(address[0].street + ", " + address[0].name + "\n" + address[0].district, coordenadas.x); + if (address[0] != undefined) { + setCurrentLocation(address[0].street + ", " + address[0].name + "\n" + address[0].district, coordenadas.x); + } + else{//Quando o usuário não da permissão de acesso da localização o geoCode retorna um array vazio + setCurrentLocation("Erro ao carregar localização", coordenadas.x); + } //console.log(currentLocation); }; diff --git a/src/app/database/databaseLoader.js b/src/app/database/databaseLoader.js index 2aa06aa..890ebd8 100644 --- a/src/app/database/databaseLoader.js +++ b/src/app/database/databaseLoader.js @@ -18,8 +18,8 @@ function transaction(db, query, values) { }); } -function insertFloodZone({ images, description, passable, location, date, time }) { - const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable, Date, Time) VALUES(?, ?, ?, ?, ?, ?, ?);`; +function insertFloodZone({ images, description, passable, location, date, time, address }) { + const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable, Date, Time, Address) VALUES(?, ?, ?, ?, ?, ?, ?, ?);`; if (location === undefined) { console.debug("undefined location"); return; @@ -33,13 +33,14 @@ function insertFloodZone({ images, description, passable, location, date, time } parseInt(passable), moment(date).format("DD/MM/YYYY"), moment(time).format("HH:MM"), + address, ]; transaction(global.userDataBase, query, values); } -function insertPluviometerData({ pluviometer, images, dateTime, time, location }) { - const query = `INSERT INTO Pluviometer(Date, Images, Latitude, Longitude, Precipitation) VALUES(?, ?, ?, ?, ?);`; +function insertPluviometerData({ pluviometer, images, dateTime, time, location, address }) { + const query = `INSERT INTO Pluviometer(Date, Images, Latitude, Longitude, Precipitation, Address) VALUES(?, ?, ?, ?, ?, ?);`; if (location === undefined) { console.debug("undefined location"); @@ -52,13 +53,14 @@ function insertPluviometerData({ pluviometer, images, dateTime, time, location } parseFloat(location["latitude"]), parseFloat(location["longitude"]), parseFloat(pluviometer), + address, ]; transaction(global.userDataBase, query, values); } -function insertRainData({ images, description, rain, location, date, time }) { - const query = `INSERT INTO RainLevel(RainIdx, Description, Images, Latitude, Longitude, Date, Time) VALUES(?, ?, ?, ?, ?, ?, ?);`; +function insertRainData({ images, description, rain, location, date, time, address }) { + const query = `INSERT INTO RainLevel(RainIdx, Description, Images, Latitude, Longitude, Date, Time, Address) VALUES(?, ?, ?, ?, ?, ?, ?, ?);`; if (location === undefined) { console.debug("undefined location"); @@ -73,6 +75,7 @@ function insertRainData({ images, description, rain, location, date, time }) { parseFloat(location["longitude"]), moment(date).format("DD/MM/YYYY"), moment(time).format("HH:MM"), + address, ]; console.log(values); @@ -80,8 +83,8 @@ function insertRainData({ images, description, rain, location, date, time }) { transaction(global.userDataBase, query, values); } -function insertRiverData({ images, description, riverScale, location, date, time }) { - const query = `INSERT INTO RiverLevel(RiverIdx, Description, Images, Latitude, Longitude, Date, Time) VALUES(?, ?, ?, ?, ?, ?, ?);`; +function insertRiverData({ images, description, riverScale, location, date, time, address }) { + const query = `INSERT INTO RiverLevel(RiverIdx, Description, Images, Latitude, Longitude, Date, Time, Address) VALUES(?, ?, ?, ?, ?, ?, ?, ?);`; if (location === undefined) { console.debug("undefined location"); @@ -96,6 +99,7 @@ function insertRiverData({ images, description, riverScale, location, date, time parseFloat(location["longitude"]), moment(date).format("DD/MM/YYYY"), moment(time).format("HH:MM"), + address, ]; console.log(values); diff --git a/src/app/database/db.js b/src/app/database/db.js index 09cf1f6..daf4414 100644 --- a/src/app/database/db.js +++ b/src/app/database/db.js @@ -9,7 +9,8 @@ const init_queries = [ Longitude real NOT NULL, Passable INTERGER NOT NULL, Date text, - Time text + Time text, + Address text );`, `CREATE TABLE IF NOT EXISTS Pluviometer ( Id integer PRIMARY KEY autoincrement, @@ -18,7 +19,8 @@ const init_queries = [ Latitude real NOT NULL, Longitude real NOT NULL, Precipitation real NOT NULL, - Time text + Time text, + Address text );`, `CREATE TABLE IF NOT EXISTS RainLevel ( Id integer PRIMARY KEY autoincrement, @@ -28,7 +30,8 @@ const init_queries = [ Latitude real NOT NULL, Longitude real NOT NULL, Date text, - Time text + Time text, + Address text );`, `CREATE TABLE IF NOT EXISTS RiverLevel ( Id integer PRIMARY KEY autoincrement, @@ -38,7 +41,8 @@ const init_queries = [ Latitude real NOT NULL, Longitude real NOT NULL, Date text, - Time text + Time text, + Address text );`, ]; diff --git a/src/app/screens/PluviometerSharingDataScreen.js b/src/app/screens/PluviometerSharingDataScreen.js index 729c3bc..a2434fb 100644 --- a/src/app/screens/PluviometerSharingDataScreen.js +++ b/src/app/screens/PluviometerSharingDataScreen.js @@ -39,6 +39,7 @@ function PluviometerSharingDataScreen(props) { context.defaultLocation(); }, []); const location = context.eventCoordinates; + const address = context.eventLocation; const [dateTime, setDateTime] = useState(moment()); const [time, setTime] = useState(moment()); @@ -52,7 +53,7 @@ function PluviometerSharingDataScreen(props) { images: [], }} onSubmit={(values) => { - insertPluviometerData({ ...values, dateTime, time, location }); + insertPluviometerData({ ...values, dateTime, time, location, address }); console.log("DATA:" + dateTime); console.log("HORA:" + time); showMessage({ diff --git a/src/app/screens/RainSharingDataScreen.js b/src/app/screens/RainSharingDataScreen.js index 5bf79aa..278185b 100644 --- a/src/app/screens/RainSharingDataScreen.js +++ b/src/app/screens/RainSharingDataScreen.js @@ -40,6 +40,7 @@ function RainSharingDataScreen(props) { }, []); const location = context.eventCoordinates; + const address = context.eventLocation; return ( @@ -53,7 +54,7 @@ function RainSharingDataScreen(props) { setError(true); return; } - insertRainData({ ...values, rain, location, date, time }); + insertRainData({ ...values, rain, location, date, time, address }); showMessage({ message: "Informação enviada!", duration: 1950, diff --git a/src/app/screens/RiverFloodSharingDataScreen.js b/src/app/screens/RiverFloodSharingDataScreen.js index 11c8a54..90e976e 100644 --- a/src/app/screens/RiverFloodSharingDataScreen.js +++ b/src/app/screens/RiverFloodSharingDataScreen.js @@ -40,6 +40,7 @@ function RiverFloodSharingDataScreen(props) { context.defaultLocation(); }, []); const location = context.eventCoordinates; + const address = context.eventLocation; const [error, setError] = useState(false); @@ -64,7 +65,7 @@ function RiverFloodSharingDataScreen(props) { setError(true); return; } - insertRiverData({ ...values, riverScale, location, date, time }); + insertRiverData({ ...values, riverScale, location, date, time, address }); showMessage({ message: "Informação enviada!", duration: 1950, diff --git a/src/app/screens/SharingFloodZonesScreen.js b/src/app/screens/SharingFloodZonesScreen.js index 897c550..997b44b 100644 --- a/src/app/screens/SharingFloodZonesScreen.js +++ b/src/app/screens/SharingFloodZonesScreen.js @@ -38,6 +38,7 @@ function SharingFloodZonesScreen(props) { const [time, setTime] = useState(moment()); const context = useContext(EventLocationContext); + const address = context.eventLocation; useEffect(() => { context.defaultLocation(); @@ -60,7 +61,7 @@ function SharingFloodZonesScreen(props) { setError(true); return; } - submitForm({ ...values, passable, location, date, time }); + submitForm({ ...values, passable, location, date, time, address }); console.log("DATA: " + moment(date).format("DD/MM/YYYY")); console.log("HORA: " + moment(time).format("HH:MM")); showMessage({