我已经将我的应用程序连接到google places API,我一直工作到某一点(我不确定发生了什么变化),但API不再接收我的请求,当我去检查谷歌开发人员控制台时,我既没有显示4XX或2XX(以前显示)
这是我的代码
import React,{useState,useEffect} from "react";
import { View ,Text, TextInput ,SafeAreaView, ListView } from "react-native";
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
import { useNavigation } from "@react-navigation/core";
import Styles from "./style";
import Place from "./PlaceRow";
const HomePlace={
description:"Home",
geometry:{location:{lat:48.8152937,lng:2.4597668}}
};
const WorkPlace={
description:"Work",
geometry:{location:{lat:48.8152837,lng:2.4597659}}
};
const DestinationSearch=(props)=>{
const navigation= useNavigation();
const [fromText , setFromText] = useState("");
const [destinationText , setDestinationText] = useState("");
useEffect(() => {
if(fromText && destinationText) {
navigation.navigate("SearchResults",{
fromText,
destinationText
})
}
}, [fromText,destinationText]);
return (
<SafeAreaView>
<View style={Styles.container}>
<GooglePlacesAutocomplete
placeholder="From"
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
setFromText(data, details);
}}
currentLocation={true}
currentLocationLabel='Current location'
styles={{
textInput:Styles.TextInput,
container:{
position:"absolute",
top:0,
left:10,
right:10,
},
listView:{
position:"absolute",
top:100,
}
}}
query={{
key: 'API CREDENTIALS',
language: 'en',
}}
predefinedPlaces={[HomePlace,WorkPlace]}
renderRow={(data)=><Place data={data}/>}
/>
<GooglePlacesAutocomplete
placeholder="Where to?"
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
setDestinationText(data, details);
}}
styles={{
textInput:Styles.TextInput,
container:{
position:"absolute",
top:55,
left:10,
right:10,
}
}}
query={{
key: 'API CREDENTIALS',
language: 'en',
}}
predefinedPlaces={[HomePlace,WorkPlace]}
renderRow={(data)=><Place data={data}/>}
/>
<View style={Styles.circle}/>
<View style={Styles.line}/>
<View style={Styles.square}/>
</View>
</SafeAreaView>
);
};
export default DestinationSearch;
我试过了
使用- 提供的测试代码react-native-google-places-autocomplete
- 创建新的API凭据
- 等待数天,以防服务器宕机
- 重新安装NPM包
- 重新启用Google Places API
我解决了这个问题,原来我的android工作室模拟器断开了它的wifi(被卡住的愚蠢理由)