Geolocation with API .... how to save two points?

Asked

Viewed 20 times

-2

Can you help? In the field audit module, by clicking CHECKIN, save the latitude and longitude of the device.

The API already exists and the table already contains the columns from latitude to longitude. Check-in - at the beginning of the visit: value 1 Check-in - at the end of the visit: value 2

After pressing Check IN first save on the device, at the end of the visit it overwrites and saves the output, not the input. I need to save input and output too

Call the checkout by clicking finish the checklist (all checklists)

The logic is: So ... I need to do when the "Auditor" presses the "Checkin" button to save and send the JSON from the input in place. As I put there in the "body" with the information of the "type". Checkin - When You Start Your Visit: Add "value 1" with first JSON At the end of your visit, Checkout, where you send it back to the API without overwriting Checkout - at the end of your visit: Add "value 2" to JSON

export const checkIn = async ({
  cdFilial,
  nrLatitude,
  nrLongitude,
  tipo,
  justificativa,
  dataHora,
  token
}) => {
  const url = `${endpoint.auditoria.checkInOut}`;

  return await request(
    'put',
    url,
    getHeader(token),
    JSON.stringify({
      cdFilial,
      nrLatitude,
      nrLongitude,
      tipo,
      justificativa,
      dataHora
    })
  );
}

export default CheckIn = ({ onCheckIn, data, keys, filteredKeys, filter }) => {

    const { showLoading, user } = useContext(appContext);

    const handleCheckIn = async () => {
        getCurrentPosition(
            doCheckIn,
            (error) => {
                console.log(error.code, error.message);
            });
    }

    const doCheckIn = async (position) => {
        showLoading(true);
        const { storeId } = data;
        const { latitude: nrLatitude, longitude: nrLongitude } = position.coords;
        const dataHora = moment(new Date()).format('DDMMYYYY_HHmmss');
        checkIn({ token: user.token, tipo: 1, cdFilial: storeId, nrLatitude, nrLongitude, dataHora })
            .then(res => {
                showLoading(false);
            showLoading(false);          
                showLoading(false);
                if (res.status == 200) {
                    Toast.show({ text: res.data.message, type: 'success', duration: 5000, buttonText: 'Ok' });
                Toast.show({ text: res.data.message, type: 'success', duration: 5000, buttonText: 'Ok' });                
                    Toast.show({ text: res.data.message, type: 'success', duration: 5000, buttonText: 'Ok' });
                    onCheckIn();
                };
            });
    }

const finishReport = async () => {
    showLoading(true);
    getCurrentPosition(
      async (position) => {
        const { latitude: nrLatitude, longitude: nrLongitude } = position.coords;

        // Add signatures to each report
        let finishedReports = cleanReportObject(reports);
        console.log('filtered finished reports = ', finishedReports);

        const toApi = {
          id: data.storeId + data.date,
          cdFilial: data.storeId,
          cdOperador: user.cdOperador,
          dtGeracao: new Date(),
          nrLatitude,
          nrLongitude,
          conteudo: JSON.stringify(finishedReports)
        }
        console.log('toApi = ', toApi);
        console.log('finishedReports = ', finishedReports);

        NetInfo.fetch().then(state => {
          console.log("Is connected?", state.isConnected);
          if (state.isConnected) {
            delete toApi.id;
            sendReports(user.token, toApi)
              .then(res => {
                showLoading(false);
                if (res.status == 200) {
                  closeConfirmation();
                  finishScheduleData(data.date, data.storeId);
                  Toast.show({ text: res.data.message, type: 'success' });
                  navigation.goBack();
                };
              });
          } else {
            AuditoriaRealmService.save(toApi);
            closeConfirmation();
            showLoading(false);
            navigation.goBack();
          }
        });
      },
      (error) => {
        showLoading(false);
        console.log(error.code, error.message);
      }
    )
  }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.