Setting
The first thing you should do is create a new Game Object in a scene and add the component ‘True Weather’ to it. There should only be a single instance of the component in your scene.
Once added you will see something like this:

In ‘Units’ (1) you can select the metric system you want to use: Metric (International System of Units or SI) or Imperial.
If ‘Try GPS first’ (2) is active, the geolocation service will try to use GPS hardware. This is normally only possible on mobile devices and if the application has the permissions to use it. If available, this mode can save battery life.
Only the GPS is activated during the query and the mode with less precision (~500 meters) is used.
If this option is not active, or is not available, the web service ipap.co will be used. This service does not require registration to use it for less than 1000 consultations per day. Anyway, I recommend you register when your game is public. Once you register, they will provide you with a key that you must put in ‘API Key’ (3).
To obtain meteorological data, you can use the web services of openweathermap.com (basic data) or climacell.co (more data). Select the one you want to use in ‘Service’ (4).
Both services require web registration, even for free use. In the case of openweathermap.com you need to sign up for their ‘Current weather’ service. If you choose climacell.co you must sign up for their ‘Weather API’ service. The key that they provide you, you must put in ‘API Key’ (5).
Do you want to use another service? Here you have some of the best current services, tell me which one you want to use and I will include it in an update.
Use
All the code is inside the namespace ‘Nephasto.TrueWeatherAsset’ and the main component is ‘TrueWeather’. The first thing you should do is import the namespace:
|
|
If you have already created a Game Object with the component ‘TrueWeather’ in the Editor, you can access it like this:
|
|
To detect the current time you must call the function ‘Detect()’. As the information may take a few seconds to be available, you must use an Action as a parameter that will be executed when the query is finished. For example, if you want to get a message through the console with the temperature it would be something like this:
|
|
Once the Action is called without errors, you can access the geolocation with the ‘Location’ property and the weather information with ‘Weather':
|
|
All this information will be available until the next time you call ‘Detect()’. To find out all the data you have available, you can consult the files ‘Runtime/ILocation.cs’ (geolocation) and ‘Runtime/WeatherService.cs’ (meteorology).
Some services provide extra information that you can know by casting the generic data to the service used. If you use the service ipap.co for geolocation you can access the extra data like this:
|
|
Check all the extra data available by looking at the file ‘Runtime/IPAPI/IPAPILocation.cs’.
When you use the service openweathermap.com you can access its extra data like this:
|
|
Check all the extra data available in the file ‘Runtime/OpenWeatherMap/OpenWeatherMapService.cs’.
If you use the service climacell.co, you can do it like this:
|
|
You can also access air quality data (not available using openweathermap.com), like this:
|
|
Check all the extra data available by looking at the file ‘Runtime/Climacell/ClimacellService.cs’.
Any questions or suggestions you have, I will be happy to answer you in
