Need help with openweathermap {"cod": "400", "message": "nothing to geocode"}

Hi.

I am trying to get the user input working for my Unity project.

In the image below when I type in a city name, it should display right below the input field, the name of the city inputted and at the corner of the image, between the input field and the button above the JSON data of the city based on the OpenWeatherMap API.

The JSON data should be something like this…

{
    "coord": {
        "lon": -84.39,
        "lat": 33.75
    },
    "weather": [
        {
            "id": 501,
            "main": "Rain",
            "description": "moderate rain",
            "icon": "10n"
        },
        {
            "id": 701,
            "main": "Mist",
            "description": "mist",
            "icon": "50n"
        },
        {
            "id": 301,
            "main": "Drizzle",
            "description": "drizzle",
            "icon": "09n"
        }
    ],
    "base": "stations",
    "main": {
        "temp": 290.79,
        "pressure": 1012,
        "humidity": 82...
etc...

But instead I am getting this result.

{"cod": "400", "message": "nothing to geocode"}

image

Below is the script I have created for the program.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Linq;
using SimpleJSON;
using UnityEngine.SceneManagement;

public class WeatherAPI : MonoBehaviour
{
    public static string currentCity;
    public static string API_KEY = "272d4a7147e89ee64c76e699bdfa2a9e";
    public InputField myUserInput;
    public Text myText;
    public string URL = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&units=&cnt=6", currentCity, API_KEY);
    public Text responseText;
    public string currentWeatherDescription = "test";
 
    public float temp;

    public void Request()
    {
        currentCity = myUserInput.text;
        myText.text = currentCity;
        WWW request = new WWW(URL);
        StartCoroutine(OnResponse(request));
    }

    public IEnumerator OnResponse(WWW req)
    {
        yield return req;
        if (req.text != null)
        {
            responseText.text = req.text;
            //WeatherEffect(req.text);
        }
        else
        {
            Debug.Log("Error" + req.error);
        }
    }

    public void WeatherEffect(string jsonString)
    {
        var weatherJson = JSON.Parse(jsonString);

        currentWeatherDescription = weatherJson["weather"][0]["description"].Value;
        currentCity = weatherJson["name"].Value;
        temp = weatherJson["main"]["temp"].AsFloat;

        switch (currentWeatherDescription)
        {
            case "few clouds":
                Debug.Log("...only a few clouds");
                SceneManager.LoadScene(8);
                break;
            case "scattered clouds":
                Debug.Log("Scattered clouds: the clouds are parting...");
                SceneManager.LoadScene(9);
                break;
            case "broken clouds":
                Debug.Log("Broken clouds: someone broke the clouds");
                SceneManager.LoadScene(1);
                break;
            case "rain":
                Debug.Log("Rain: It's either raining, or Zeus is crying");
                SceneManager.LoadScene(3);
                break;
            case "moderate rain":
                Debug.Log("Rain: It's either raining, or Zeus is crying");
                SceneManager.LoadScene(3);
                break;
            case "shower rain":
                Debug.Log("Shower rain: Another day in Oregon");
                SceneManager.LoadScene(3);
                break;
            case "thunderstorm":
                Debug.Log("Thunderstorm: Zeus is pissed off! Run for your life!");
                SceneManager.LoadScene(7);
                break;
            case "snow":
                Debug.Log("Snow day! It's a winter wonderland!");
                SceneManager.LoadScene(4);
                break;
            case "light snow":
                Debug.Log("Snow day! It's a winter wonderland!");
                SceneManager.LoadScene(4);
                break;
            case "mist":
                Debug.Log("Misty ...we might have a fog of war or some rain...");
                SceneManager.LoadScene(6);
                break;
            case "light intensity drizzle":
                Debug.Log("Drizzle: Expect some drizzle rain");
                SceneManager.LoadScene(2);
                break;
            case "light rain":
                Debug.Log("Light rain: Expect some light rain");
                SceneManager.LoadScene(2);
                break;
            default:
                Debug.Log("It's a clear sky");
                SceneManager.LoadScene(5);
                break;

        }

        //if (currentWeatherDescription == "clear sky")
        //{
        //    Debug.Log("It's a Clear Sky");
        //}

        //else
        //{
        //    Debug.Log("It's NOT!");
        //}

    }
}

Any help would be greatly appreciated. Thank you.

If you were to display URL when entering Atlanta what does it end up looking like? Is this TypeScript or something else?

It displays the link… without the city inputted.
image
…which is weird considering my string format should take it. So I’m guessing something else; considering also that I’m not familiar with TypeScript.

Since the currentCity is blank, it has something to do with how you are capturing/assigning a value to it.

What happens if you put a console.log(currentCity) after the first line of the Request function below?

    public void Request()
    {
        currentCity = myUserInput.text;
        console.log(currentCity); 
        myText.text = currentCity;
        WWW request = new WWW(URL);
        StartCoroutine(OnResponse(request));
    }

It displays the current city–Atlanta, in the debug log.

This seems like C# to me and not TypeScript.

Are there any solutions to this problem or not?
I can’t seem to move ahead of my project without solving this.

In the following, can you try adding currentCity = myUserInput.text; on a new line before you declare the URL? This may not work, because I don’t know enough about the language (TypeScript or C#).

public class WeatherAPI : MonoBehaviour
{
    public static string currentCity;
    public static string API_KEY = "272d4a7147e89ee64c76e699bdfa2a9e";
    public InputField myUserInput;
    public Text myText;
    currentCity = myUserInput.text; // you need some way to capture what is in the input box before you define URL below.
    public string URL = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&units=&cnt=6", currentCity, API_KEY);

This method will not work as the variables need to be initialized.
I’ve tried making both the InputField and the currentCity string static and assigned it to the InputField property and it says the object reference has not been set.

Any other ideas?