【发布时间】:2021-04-16 07:19:01
【问题描述】:
我想在用户使用 react-native-google-places-autocomplete 搜索位置时生成一个标记。我正在使用expo react native。目前,标记设置在固定位置。我希望根据用户通过react-native-google-places-autocomplete 提供的输入来设置它。我怎样才能做到这一点?以下是我的代码:
<View>
<GooglePlacesAutocomplete
placeholder=""
query={{
key: GOOGLE_PLACES_API_KEY,
language: 'en', // language of the results
}}
fetchDetails={true}
onPress={(data, details:any) => {
setDestinationLatitude(details.geometry.location.lat.toString());
setDestinationLongitude(details.geometry.location.lng.toString());
}}
onFail={(error) => console.error(error)}
requestUrl={{
url:
'https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api',
useOnPlatform: 'web',
}} // this in only required for use on the web. See https://git.io/JflFv more for details.
keyboardShouldPersistTaps='always'
styles={{
textInputContainer: {
width: "90%",
//top: 8,
alignSelf: 'center'
},
textInput: {
borderColor: grey,
borderWidth: 1,
borderRadius: 5,
height: 48,
paddingBottom: 8,
color: black,
fontSize: 16,
},
predefinedPlacesDescription: {
color: '#1faadb',
},
}}
/>
</View>
<View style={style.mapContainer}>
<MapView
style={style.map}
region={region}
onRegionChangeComplete={region => setRegion(region)}
>
<Marker coordinate={{
latitude: latitude ,
longitude: longitude,
}}></Marker>
</MapView>
</View>
我根据 stackoverflow 的答案尝试了其他方法,但它们似乎已经过时,我无法运行它们
【问题讨论】:
标签: android react-native google-maps expo googleplacesautocomplete