Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find weather forecast city id?

final String FORECAST_BASE_URL =
        "http://api.openweathermap.org/data/2.5/forecast/daily?";
final String QUERY_PARAM = "q";

Hello. I'm making a weather forecast app. But when I use "http://openweathermap.org"'s API, I stock in trouble how can I get the city code or ID "q"? I try to find the city ID but I can't.

Example code Call by city ID:

api.openweathermap.org/data/2.5/forecast/daily?id=524901

and I heard that "q" is used to "id" also. I mean

api.openweathermap.org/data/2.5/forecast/daily?q=524901

is also possible. i want to do like this.

So, How to find city id? Anybody knows?

like image 989
Minjung Son Avatar asked Jan 11 '15 03:01

Minjung Son


People also ask

How do I find my weather ID?

Before contacting SiriusXM, the Weather ID and Radio ID of the weather antenna will need to be determined. These numbers can be found on the bottom of the antenna.

How do I find my app ID for OpenWeatherMap?

Once you sign up using your email, the API key (APPID) will be sent to you in a confirmation email. Your API keys can always be found on your account page, where you can also generate additional API keys if needed.

How do I put cities on my Weather app?

Open the Weather app, then tap the Add icon (at the top of the screen). Enter a location in the Search city box, then tap the city you want to add. Tap Current location (at the top of the screen) to update your current location.


2 Answers

There is a similar question that was asked in the OpenWeatherMap support center. Here is the link OpenWeatherMap

Also, here is a link to the list of cities and their respective ID's (just CTRL + F to find the city you want): List of Cities & IDs

like image 182
freddiev4 Avatar answered Oct 21 '22 02:10

freddiev4


A full list of CityID's can be downloaded from: http://bulk.openweathermap.org/sample/city.list.json.gz

You can manually search that file (after unzipping it) for your city name or search from the shell like:

grep -i "london" city.list.json

Regarding the "q" vs. "id" query tags: you can search by city (and country) using the "q" tag like this:

http://api.openweathermap.org/data/2.5/forecast/daily?q=London,GB

(note that the country code isn't necessarily required)

and that works as long as there is no question about which city. If there's multiple cities of the same name in a country, though, you can use the CityID to specify a certain one after you've found the correct identifier in the list linked above like this:

http://api.openweathermap.org/data/2.5/forecast/daily?id=2643743

which also returns London's weather, but ensures you don't accidentally get the weather for London, Kentucky, USA or London, Ohio, USA if you've chosen not to use the country code in the "q" tag.

like image 35
Anson VanDoren Avatar answered Oct 21 '22 01:10

Anson VanDoren