Skip to content

Commit

Permalink
geolocalização add no formulario de cadastro #7
Browse files Browse the repository at this point in the history
  • Loading branch information
biancabsouza23 committed Jul 9, 2024
1 parent 4056006 commit a2db46f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Fronted/src/componentes/FormularioCadastro.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom'; // Importa useNavigate
import './FormularioCadastro.css';

Expand All @@ -8,10 +8,26 @@ const FormularioCadastro = () => {
username: '',
email: '',
password: '',
latitude: null,
longitude: null,
});

const navigate = useNavigate(); // Inicializa o useNavigate

useEffect(() => {
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition((position) => {
setFormData((prevFormData) => ({
...prevFormData,
latitude: position.coords.latitude,
longitude: position.coords.longitude,
}));
});
} else {
console.log("Geolocalização não é suportada neste navegador.");
}
}, []);

const handleChange = (e) => {
const { name, value } = e.target;
setFormData((prevFormData) => ({
Expand Down

0 comments on commit a2db46f

Please sign in to comment.