React Native Google API 没有响应
React Native Google API not responding
我已将我的应用程序连接到 google 个位置 API 并且我一直工作到某个时间点(我不确定发生了什么变化)但是 API 不再接收当我去检查 google 开发者控制台时,我的请求没有显示 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 个地点 API
我解决了问题,结果是我的 android studio 模拟器与它的 wifi 断开了连接
(卡住的愚蠢理由)
我已将我的应用程序连接到 google 个位置 API 并且我一直工作到某个时间点(我不确定发生了什么变化)但是 API 不再接收当我去检查 google 开发者控制台时,我的请求没有显示 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 个地点 API
我解决了问题,结果是我的 android studio 模拟器与它的 wifi 断开了连接 (卡住的愚蠢理由)