【发布时间】:2021-12-08 19:27:49
【问题描述】:
我已将我的应用程序连接到 google 地方 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
【问题讨论】:
-
也许您超出了您的帐户限制?检查您的帐户帐单。
-
我也检查过,我也在使用其他谷歌服务,他们正在工作
标签: react-native google-places-api