react-native - react-native-google-autocomplete 将结果限制为位置和半径
问题描述
有人可以向我解释如何将结果限制在某个位置周围的半径范围内吗?
使用react-native-google-autocomplete: https://github.com/EQuimper/react-native-google-autocomplete
我试图在我的代码中添加它的不同位置,但 locationResults 没有以任何方式过滤。
我在官方文档中找到了一些资源,但由于我已经在使用这个库,我希望暂时保留它
我应该使用组件、道具吗?现在我限制在用户输入末尾添加城市的结果,但它非常有限且丑陋^^
希望你能抽出时间回答我,最好的问候
我的代码如下:
<GoogleAutoComplete
apiKey="*****"
debounce={500}
predefinedPlaces={notLocatedPlace}
minLength={4}
language="fr"
components="country:fr"
// location={{lat:45.526298,lng: 4.873333}}
// radius={"20000"}
>
{({
handleTextChange,
locationResults,
fetchDetails,
isSearching,
inputValue,
clearSearchs,
// location,
// radius,
}) => (
<React.Fragment>
{console.log('locationResults', locationResults)}
<View
style={styles.adressContainer}
// style={{flexDirection:"row", justifyContent:"center", alignItems:"center"}}
>
<TextInput
underlineColorAndroid="#dfdfdf"
placeholder="Rechercher une adresse"
onChangeText={handleTextChange}
value={inputValue}
style={styles.streetInput}
/>
{/* <Button
title="clear"
onPress={clearSearchs}
style={styles.streetNumberInput}
// color="#aaa"
/> */}
</View>
{isSearching && <ActivityIndicator size="large" color="#1faadb" />}
<ScrollView>
{locationResults.map(el =>(
<LocationResultItem
{...el}
key={el.id.toString()}
fetchDetails={fetchDetails}
{...{clearSearchs}}
// query={{
// location: '45.526298, 4.873333',
// radius: '15000', //15 km
// strictbounds: true,
// }}
/>
))}
</ScrollView>
{/* <Text></Text> details a importer 2 way binding*/}
</React.Fragment>
)}
</GoogleAutoComplete>