<pre>const GooglePlacesInput = () => { const [city, setcity] = React.useState(''); useEffect(() => { console.log() }) const onRequestTagClick = async () => { const token = userSession.getAccessToken(); const requestData = { vehicle_no: "AAA", engine_no: "AAA", fuel_type: "AAA", phone: "0726618185", // address: "selected value from the GooglePlacesAutocomplete" } const fetchOptions = { method: requestMethods.REQUEST_TAG, body: JSON.stringify(requestData), headers: { 'Content-Type': 'application/json', 'Authorization': `JWT ${token}` } } // Sending request. const [response, err] = await awaitable(fetch(endpoints.REQUEST_TAG, fetchOptions)); if (err) { // Failed to complete the request. Possibly due to a network error. console.log("Network error!!!"); return; } const response_json = await response.json(); //400 if (response.status === 400) { Alert.alert( 'Warning!', 'Fail'); console.log(response_json); console.log(token); return; } //401 if (response.status === 401) { Alert.alert( 'Session Timeout!', 'Something went wrong. Please try again in few minutes or Sign in again to continue'); console.log(response_json); console.log(token); return; } if (response.status === 201) { Alert.alert( 'Success!', 'Success'); console.log(response_json); console.log(token); } } return ( <SafeAreaView style={styles.container}> <GooglePlacesAutocomplete placeholder='Search' fetchDetails={true} onPress={(data, details = null) => { // 'details' is provided when fetchDetails = true console.log(data, details); console.log('city: ' + data.description) }} query={{ key: 'AIzaSyBvMpfZgNHmFZib32x4HHLpKWstfhKhUAs', language: 'en', }} // currentLocation={true} // currentLocationLabel='Current location' /> <TouchableOpacity style={styles.commandButton} onPress={onRequestTagClick} > <Text style={styles.panelButtonTitle}>Submit</Text> </TouchableOpacity> </SafeAreaView> ); }; export default GooglePlacesInput;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)