【问题标题】:React Native Google API not respondingReact Native Google API 没有响应
【发布时间】: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


【解决方案1】:

我解决了这个问题,结果我的 android studio 模拟器与它的 wifi 断开了连接 (陷入困境的愚蠢理由)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-06
    • 2020-06-11
    • 2018-03-16
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 2022-08-19
    • 2021-06-05
    相关资源
    最近更新 更多