Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ * * * TM 3 5 2 2 3 J TMA 0 2 Q 1 , code * * 2 6 / 1 0

/**
* TM35223J TMA02 Q1, code
*
*26/10/2023 Intial version Chris Thomson
*14/12/2023 Line 74 modified to getDate rather than getDay Chris Thomson
*
* This is the main application code for the React Native application.
* It is a simple application that allows a user to register a userid
* and then make a taxi request or offer.
*
* The application uses the Expo framework to provide access to the
* device GPS and to provide a simple UI.
*
* The application uses the TaxiService library to access the taxi
* service API.
*
* The application uses the NominatimService library to access the
* Nominatim service to lookup the address of the current GPS location.
*
* The application uses the TimePicker, AddressPicker and WaitTime
* components to provide a simple UI.
**/
import { Text, TextInput, Button, SafeAreaView, View, StyleSheet } from 'react-native';
import { useState } from 'react';
import TimePicker from './components/TimePicker';
import AddressPicker from './components/AddressPicker';
import WaitTime from './components/WaitTime';
import { getLocationAddress } from './libraries/NominatimService';
import * as Taxi from './libraries/TaxiService';
import * as Location from 'expo-location';
import StackNav from './components/StackNav';
/**
* Requests user permission to get the GPS location of the device.
* This needs to be called before the GPS is read.
*
* @returns true if permission is granted, otherwise throws an error.
*/
async function getUserPermission(): Promise {
let { status }= await Location.requestForegroundPermissionsAsync();
if (status !== 'granted'){
throw('Permission to access location was denied, please check your device settings.');
} else {
return true;
}
}
export default function App(){
// State variables to hold the data entered by the user.
const [ownerAddress, setOwnerAddress]= useState("");
const [customerAddress, setCustomerAddress]= useState("");
const [ownerHours, setOwnerHours]= useState("0");
const [ownerMinutes, setOwnerMinutes]= useState("0");
const [ownerMatches, setOwnerMatches]= useState("");
const [customerHours, setCustomerHours]= useState("0");
const [customerMinutes, setCustomerMinutes]= useState("0");
const [ownerWait, setOwnerWait]= useState("0");
const [userid,setUserid]= useState("");
const [ownerOrderid,setOwnerOrderid]= useState("");
const [customerMatches, setCustomerMatches]= useState("");
//Make sure we can get the GPS location when required.
getUserPermission();
const getOwnerData = async ()=>{
// fetch the current location.
const location = await Location.getCurrentPositionAsync({});
setOwnerAddress("location found");
}
const transportOwnerMake = async ()=>{
const now = new Date();
// Create a start and end time for the order.
const start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), parseInt(ownerHours), parseInt(ownerMinutes));
const end = new Date(start.getTime()+ parseInt(ownerWait)*60000);
const order = await Taxi.postOrders(userid, start.toISOString(), end.toISOString(),"0", ownerAddress);
setOwnerOrderid(order.id);
}
const transportOwnerCancel =()=>{
if (ownerOrderid !="")
Taxi.deleteOrders(userid, ownerOrderid);
setOwnerOrderid("");
}
const transportOwnerMatches = async ()=>{
const matches = await Taxi.getMatches(userid);
setOwnerMatches(JSON.stringify(matches));
}
// The UI for the application.
return (
Owner Offer
Matches: {ownerMatches}
Customer Request
Matches: {customerMatche

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

2. Define identity.

Answered: 1 week ago