反应新的google-place-autocomplete不返回值

问题描述 投票:0回答:1

基本上,当我从列表中选择某些内容时,应将API更新为任何选择API,但事实并非如此,而不是显示错误!所以我真的不知道发生了什么!

代码:

const GooglePlacesInput = ({ onSelectAddress }) => { return ( <View style={{.. }}> <GooglePlacesAutocomplete placeholder="Search Address" minLength={2} fetchDetails={true} onPress={(data, details = null) => { console.log('Data:', data); console.log('Details:', details); // Check if details are present if (details) { try { // Extract the formatted address const address = details.formatted_address; // Extract latitude and longitude const lat = details.geometry.location.lat; const lng = details.geometry.location.lng; console.log('Selected Address:', address); console.log('Coordinates:', lat, lng); // Call the onSelectAddress function with the address and coordinates onSelectAddress({ address: address, latitude: lat, longitude: lng, }); } catch (error) { console.error('Error extracting address details:', error); } } else { console.warn('No details available for the selected location.'); } }} query={{ key: 'XXXXXXXXXXXXXXXXX', language: 'en', }} styles={{ ..} /> </View> ); };

在父组件中使用:

  const handleShopAddressUpdate = (data) => {
    console.log('Received address:', data); // Log the data received
    setShopAddress(data.address);
    console.log('Updated shopAddress:', data.address); // Verify the updated state
  };

 <GooglePlacesInput
              onSelectAddress={handleShopAddressUpdate} 
            />

即将其从文档中使用不起作用:

   <GooglePlacesAutocomplete
      placeholder='Search'
      onPress={(data, details = null) => {
        // 'details' is provided when fetchDetails = true
        console.log(data, details);
      }}
      query={{
        key: 'YOUR API KEY',
        language: 'en',
      }}
    />

,再次,Google的另一个车牌库,事实证明,像Google的每种产品一样,图书馆有问题,因此我必须在AI的帮助下手动执行解决方案:
react-native expo react-google-autocomplete
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.