Click here to Skip to main content
14,929,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
<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;


What I have tried:

I try to use the onChangetext() function but it doesn't work so i want to know how to pass the selected value from auto complete to the API
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900