2017-06-16 15 views
1

レスキューネイティブで書かれた天気アプリでは、アプリがiOSで正常に動作している間にAndroidで「ネットワークリクエストが失敗しました」というエラーが表示されます。ここでネットワークリクエストが失敗しました

enter image description here

がフェッチ機能です -

componentDidMount: function() { 
    navigator.geolocation.getCurrentPosition(
    location => { 
     // this variable will contain the full url with the new lat and lon 
     var formattedURL = REQUEST_URL + "lat=" + location.coords.latitude + "&lon=" + location.coords.longitude+"&APPID=e5335c30e733fc682907a126dab045fa"; 

     // this will output the final URL to the Xcode output window 
     console.log(location.coords.latitude); 
     console.log(location.coords.longitude); 
     console.log(formattedURL); 

     // get the data from the API 
     this.fetchData(formattedURL); 

     }, 
    error => { 
     console.log(error); 
    }); 
    }, 

    // fetchdata takes the formattedURL, gets the json data and 
    // sets the apps backgroundColor based on the temperature of 
    // the location 
    fetchData: function(url) { 
    fetch(url) 
     .then((response) => response.json()) 
     .then((responseData) => { 

     // set the background colour of the app based on temperature 
     var bg; 
     var temp = parseInt(responseData.main.temp); 
     if(temp < 14) { 
      bg = BG_COLD; 
     } else if(temp >= 14 && temp < 25) { 
      bg = BG_WARM; 
     } else if(temp >= 25) { 
      bg = BG_HOT; 
     } 

     // update the state with weatherData and a set backgroundColor 
     this.setState({ 
      weatherData: responseData, 
      backgroundColor: bg 
     }); 
     }) 
     .done(); 
    }, 

また、私はStackOverflowの上ここでは他の質問を参照しているが、それらはすべて、127.0.0.1のようなあなたのローカルIPアドレスにローカルホストを変更する中心に展開します。私の場合、私はlocalhostを使う場所がありません。

+0

エミュレータまたは物理デバイスでテストしています –

+0

@RaviRaj Nougatを実行しているNexus 6Pのエミュレータでテストしています。 –

+1

あなたのエミュレータに隣接するあなたのアンドロイドエミュレータのオプションパネルをチェックしてください。それで、より多くのオプションがあり、セルラーに行き、データステータスとネットワークタイプをチェックしてください。ネットワークの種類を「フル」に、データの状態を「ホーム」に変更してみてください。それが動作しているか確認してください。 –

答えて

1

あなたがよりオプションは、その後携帯に行くとデータのステータスネットワークタイプをチェックする必要がありますように、あなたのエミュレータに隣接して、あなたののAndroidエミュレータオプションパネルを確認してください。ネットワークタイプを'フル'に、データステータスを'ホーム'に変更してみてください。ネットワークタイプとデータステータスのさまざまなオプションを試してみてください。

関連する問題