B4A Library ICOSWorldForecast 3.50

View attachment 14755 View attachment 14754 View attachment 16846 Hi guys, ICOSWorldForecast is here.


It's a pleasure to introduce the new library of weather forecast.

The zip include:

The library, and the demo

INSTALLATION:

Copy the Library in your Basic For Android Library.

Copy the folder weathericon is located in files in the demo. In your one.


RENAME:
ICOSWorldForecast2.71.part1.zip and ICOSWorldForecast2.71.part2.zip

TO:
ICOSWorldForecast2.71.part1.rar and ICOSWorldForecast2.71.part1.rar

In this version I add WeatherUrl and 2 more days forecast.

You can use your own icons, instead of my icons.

For this new version 2.71 you need the new key.

You must register to obtain the new key, otherwise you will get error.

Use the address below to register.

World Weather Online - Welcome to the World Weather Online Developer Network!

don't forget to replace the ApiKey="XXXXXXXXXXXXXX" with your private key

This demos, I made with my galaxy tab 7 600x1024

any question or bugs please report to me.

big Thx to warwound for is fantastic auto-generated reference.


ICOSWorldForecast
Author:
Giuseppe Salvi
Version: 2.81
  • ICOSWorldForecast
    Methods:
    • FCDate (index As Int) As String
      Return Date for which the weather is forecasted
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCDate(0)
    • FCIcon (index As Int) As Bitmap
      Return Weather symbol image
      example:
      Dim a As ICOSWorldForecast
      Image1.SetBackgroundImage=a.FCWeatherIcon(0)
    • FCIconUrl (index As Int) As String
      Return URLIcon For Forecast Condition
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCIconUrl(0)
    • FCPrecipitationMM (index As Int) As String
      Return Precipitation amount in millimeter
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCPrecipitationMM(0)
    • FCTempMaxCelsius (index As Int) As String
      Return Day and night max temperature in Celcius
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCTempMaxCelsius(0)
    • FCTempMaxFahrenheit (index As Int) As String
      Return Day and night max temperature in Fahrenheit
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCTempMaxFahrenheit(0)
    • FCTempMinCelsius (index As Int) As String
      Return Day and night min temperature in Celcius
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCTempMinCelsius(0)
    • FCTempMinFahrenheit (index As Int) As String
      Return Day and night max temperature in Fahrenheit
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCTempMinFahrenheit(0)
    • FCWeatherCode (index As Int) As String
      Return Weather Code
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWeatherCode(0)
    • FCWeatherDesc (index As Int) As String
      Return Weather description
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWeatherDesc(0)
    • FCWinddir16Point (index As Int) As String
      Return 16-Point compass wind direction
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWinddir16Point(0)
    • FCWinddirDegree (index As Int) As String
      Return Wind direction in degree
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWinddirDegree(0)
    • FCWinddirection (index As Int) As String
      Return Compass Wind direction
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWinddirection(0)
    • FCWindspeedKmph (index As Int) As String
      Return Wind speed in kilometer per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWindspeedKmph(0)
    • FCWindspeedMiles (index As Int) As String
      Return Wind speed in Miles per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWindspeedMiles(0)
    • FindLatAndLong As String
      Retrieve accurate latitude and longitude from GPS or network services
    • FindLocation As String
      Retrieve accurate location from GPS or network services
    • Full7DayName (day As Int) As String
      Return Full name of the day ( Monday )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Full7DayName(0) ' 0 = today - 1 = tomorrow etc etc
    • GetList (mCity As String) As ArrayList
      Set the City Name you wish to get the weather
      example:
      Dim a As ICOSWorldForecast
      Dim l As List
      Dim lv1 As ListView
      l = a.GetList("Los Angeles")
      For n = 0 To l.Size-1
      lv1.AddSingleLine(l.Get(n))
      Next
      Sub lv1_ItemClick (Position As Int, Value As Object)ics.CityName = lv1.GetItem(Position)
      lv1.Clear
      End Sub
    • Initialize (EventName As String)
      Initilize the object
    • Short7DayName (day As Int) As String
      Return Short name of the day ( Mon )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Short7DayName(0) ' 0 = today - 1 = tomorrow etc etc
    • StringFormat (format As String, object As Object, object1 As Object) As String
      Return Formatted String
      example:
      Label1.Text=StringFormat("Lat: %1$s - Long: %2$s ",Latitude,Longitude)
    • isWiFiConnected As Boolean
      Check if WiFi is Connected
    Permissions:
    • android.permission.ACCESS_ASSISTED_GPS
    • android.permission.ACCESS_COARSE_LOCATION
    • android.permission.ACCESS_FINE_LOCATION
    • android.permission.ACCESS_GPS
    • android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.ACCESS_WIFI_STATE
    • android.permission.CONTROL_LOCATION_UPDATES
    • android.permission.INTERNET
    Properties:
    • ApiKey As String [write only]
      Set your personal ApiKey
      example:
      Dim a As ICOSWorldForecast
      a.ApiKey="XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    • AreaName As String [read only]
      Return Name of the city
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.AreaName
    • CCCloudCover As String [read only]
      Return Cloud Cover in %
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCCloudCover
    • CCHumidity As String [read only]
      Return Humidity in %
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCHumidity
    • CCIcon As Bitmap [read only]
      Return Weather symbol image
      example:
      Dim a As ICOSWorldForecast
      Image1.SetBackgroundImage=a.CCWeatherIcon
    • CCIconUrl As String [read only]
      Return URLIcon For Current Condition
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCIconUrl
    • CCLocalObsDateTime As String [read only]
      Return Local Observation date and time
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCLocalObsDateTime
    • CCObservationTime As String [read only]
      Return Observation time (UTC)
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCObservationTime
    • CCPrecipitationMM As String [read only]
      Return Precipitation Amount in Millimeter
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.PrecipitationMM
    • CCPressure As String [read only]
      Return Atmospheric pressure in Milibars
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCPressure
    • CCTempCelsius As String [read only]
      Return Temperature in Celsius
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCTempCelsius
    • CCTempFahrenheit As String [read only]
      Return Temperature in Fahrenheit
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCTempFahrenheit
    • CCVisibility As String [read only]
      Return Visibility kilometers per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCVisibility
    • CCWeatherCode As String [read only]
      Return Weather Code
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWeatherCode
    • CCWeatherDescription As String [read only]
      Return Weather Description
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWeatherDescription
    • CCWinddir16Point As String [read only]
      Return 16-Point wind direction compass
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWinddir16Point
    • CCWinddirDegree As String [read only]
      Return Wind direction in degree
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWinddirDegree
    • CCWindspeedKmph As String [read only]
      Return Wind speed in kilometer per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWindspeedKmph
    • CCWindspeedMiles As String [read only]
      Return Wind speed in Miles per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWindspeedMiles
    • CityName As String [write only]
      Set City you wish to get the weather
      example:
      Dim a As ICOSWorldForecast
      a.CityName="New York"
    • Country As String [read only]
      Return Name of the Country
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Country
    • CurrentDate As String [read only]
      Return Current Day,Month,Year ( Friday, 28 September, 2012 )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CurrentDate
    • CurrentTime As String [read only]
      Return Current time ( 02.09 PM )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CurrentTime
    • DstOffset As String [read only]
      Return DstOffset = ( GMT +2 )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.DstOffset
    • GmtOffset As String [read only]
      Return GmtOffset = ( GMT +1 )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.GmtOffset
    • LatAndLong As String [write only]
      Set Lat and Long you wish to get the weather
      example:
      Dim a As ICOSWorldForecast
      a.LatAndLong="40.714,-74.006"
    • Latitude As Object [read only]
      Return Latitude of the city
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Latitude
    • Longitude As Object [read only]
      Return Longitude of the city
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Longitude
    • Population As String [read only]
      Return Population of the city
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Population
    • Region As String [read only]
      Return Name of the Region
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Region
    • Sunrise As String [read only]
      Return Sunrise = 06:04
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Sunrise
    • Sunset As String [read only]
      Return Sunset = 19:36
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Sunset
    • TimeZoneID As String [read only]
      Return TimeZoneID = Europe/Rome
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.TimeZoneID
    • Version As Double [read only]
      Return the version of this library
    • WeatherUrl As String [read only]
      Return url of the city [ http://www.worldweatheronline.com/London-weather/City-of-London-Greater-London/GB.aspx ]
      example:
      Dim Webview1 As Webview
      Webview1.LoadUrl(a.WeatherUrl)
 

Attachments

  • ICOSWorldForecast_DEMO.part1.zip
    293 KB · Views: 983
  • ICOSWorldForecast_DEMO.part2.zip
    167.1 KB · Views: 787
  • Main.png
    Main.png
    86.8 KB · Views: 936
  • Widget.jpg
    Widget.jpg
    81.8 KB · Views: 922
  • ICOSWorldForecast.png
    ICOSWorldForecast.png
    156.3 KB · Views: 983
  • ICOSWorldForecastFree_v3.50_lib_fix.zip
    53.9 KB · Views: 532
Last edited:

Laurent95

Active Member
Licensed User
Longtime User
Ciao Giuseppe,

SOLVED: I was calling .CCIcon before any other propery like i.e. .CCWeatherDescription.
Is this a bug?

Hello,
No nothing is related with calling anything other first.
Two possibilities, you call for the data so quick and the time response of website is a bit long, that depends of the bandwith.
In this case, the error aren't returned in library, Android generates an error code who is related with the line of code who is executed at this time.
Or you access to your file without the good command line.
Have you put access to the file in the "Asset" folder first ?
An example below :
LoadBitmapSample(File.DirAssets,"weathericon/wsymbol_0041_clear_intervals_night.png",img2.Width,img2.Height)
 
Last edited:

pantaraf

Member
Licensed User
Longtime User
Hello,
No nothing is related with calling anything other first.
Two possibilities, you call for the data so quick and the time response of website is a bit long, that depends of the bandwith.
In this case, the error aren't returned in library, Android generates an error code who is related with the line of code who is executed at this time.
Or you access to your file without the good command line.
Have you put access to the file in the "Asset" folder first ?
An example below :
LoadBitmapSample(File.DirAssets,"weathericon/wsymbol_0041_clear_intervals_night.png",img2.Width,img2.Height)
Thanks Laurent, I've missed to load the icons in the files tab.
I've another question tough... :D
How can I know if the city I'm looking for does exist, without raising an exception?
Let me explain with an example: I've got an edit where I type the name of the city I'm looking for and a button I push to start data fetching.

1 Sub btnFetch_Click
2 Dim l As List
3 If(edtCity.Text.Length>0) Then
4 Meteo.CityName=edtCity.Text
5 l=Meteo.GetList(edtCity.Text)
6 If(l.Size=1) Then
7 Meteo.CityName=edtCity.Text
8 imgIcon.SetBackgroundImage(Meteo.CCIcon)
9 lblDesc.Text=Meteo.CCWeatherDescription
10 lblTemp.Text=Meteo.CCTempCelsius
11 lblUmidity.Text=Meteo.CCHumidity
12 Else If(l.Size>1) Then
13 'More than 1 city found
14 Else
15 Msgbox("No city by that name.","")
16 End If
17 End If
18 End Sub

On a wrong edtCity.Text (non existent city or typo) I receive an exception at row 4, I've tried to skip row 4 but I always get an error and the app quits at row 5.
Even Giuseppe's demo exits abnormally if the typed text is nonsense.
Does a method exist to find if the requested city is existent or not?

Thank you!
Raffaele
 

Laurent95

Active Member
Licensed User
Longtime User
Thanks Laurent, I've missed to load the icons in the files tab.
I've another question tough... :D
How can I know if the city I'm looking for does exist, without raising an exception?
.../...
On a wrong edtCity.Text (non existent city or typo) I receive an exception at row 4, I've tried to skip row 4 but I always get an error and the app quits at row 5.
Even Giuseppe's demo exits abnormally if the typed text is nonsense.
Does a method exist to find if the requested city is existent or not?

Thank you!
Raffaele


Hello Raffaele,

You can't know if the city exist, it's why you raise also an error with the demo
You must catch the error. The "Try/Catch/End Try" allows you to catch and manage errors in B4A.
In case you use the "catch" without anything after, put at least the below line code between Catch and End Try.
Log(LastException.Message)

Try this code below, i think that will resolve your problem.

And please use "CODE .../... /CODE" between braquets, when you put code that is most clear in the forum, thank you. I means the both between, i can't show you otherwise the forum take it for code and you don't show my text, sorry, you can use the icon who have inside <> also.

Good programming.
Regards.

B4X:
1 Sub btnFetch_Click
2  Dim l As List
3  If(edtCity.Text.Length>0) Then
4  (new) Try
5                Meteo.CityName=edtCity.Text
6                l=Meteo.GetList(edtCity.Text)
7                If (l.Size=1) Then
X                     ' Meteo.CityName=edtCity.Text -> No, don't do that again.
'For more than one reason, because you send a new request on the website.
'You can have change and the datas can be unaccessible, then, you raise another error.
'You can have an overflow if many people use your program, believe me :=)
8                     imgIcon.SetBackgroundImage(Meteo.CCIcon)
9                     lblDesc.Text=Meteo.CCWeatherDescription
10                    lblTemp.Text=Meteo.CCTempCelsius
11                    lblUmidity.Text=Meteo.CCHumidity
12               Else If(l.Size>1) Then
13                   'More than 1 city found
14               Else
15                   Msgbox("No city by that name.","")
16               End If
17 (new)  Catch
18 (new)      Msgbox("No city found with this name, try another, or maybe correct the spelling.","")
19 (new)  End try
20  End If
21 End Sub
 
Last edited:

pantaraf

Member
Licensed User
Longtime User
Hello Raffaele,

You can't know if the city exist, it's why you raise also an error with the demo
You must catch the error. The "Try/Catch/End Try" allows you to catch and manage errors in B4A.
In case you use the "catch" without anything after, put at least the below line code between Catch and End Try.
Log(LastException.Message)

Try this code below, i think that will resolve your problem.

And please use "CODE .../... /CODE" between braquets, when you put code that is most clear in the forum, thank you. I means the both between, i can't show you otherwise the forum take it for code and you don't show my text, sorry, you can use the icon who have inside <> also.

Good programming.
Regards.

B4X:
1 Sub btnFetch_Click
2  Dim l As List
3  If(edtCity.Text.Length>0) Then
4  (new) Try
5                Meteo.CityName=edtCity.Text
6                l=Meteo.GetList(edtCity.Text)
7                If (l.Size=1) Then
X                     ' Meteo.CityName=edtCity.Text -> No, don't do that again.
'For more than one reason, because you send a new request on the website.
'You can have change and the datas can be unaccessible, then, you raise another error.
'You can have an overflow if many people use your program, believe me :=)
8                     imgIcon.SetBackgroundImage(Meteo.CCIcon)
9                     lblDesc.Text=Meteo.CCWeatherDescription
10                    lblTemp.Text=Meteo.CCTempCelsius
11                    lblUmidity.Text=Meteo.CCHumidity
12               Else If(l.Size>1) Then
13                   'More than 1 city found
14               Else
15                   Msgbox("No city by that name.","")
16               End If
17 (new)  Catch
18 (new)      Msgbox("No city found with this name, try another, or maybe correct the spelling.","")
19 (new)  End try
20  End If
21 End Sub
Thank you a lot Laurent.
Sorry, I've completely missed the CODE feature.:oops:

Ciao.
Raffaele
 

pantaraf

Member
Licensed User
Longtime User
Ciao Giuseppe,
I'm trying to use the FindLocation and AreaName feature to find the actual position of the user.
B4X:
If(Meteo.FindLocation.Length>0) Then
    Try
      Dim city As String
      city= Meteo.FindLocation
      Meteo.CityName=Meteo.AreaName
      edtLoc.Text=Meteo.AreaName
      MeteoUpdate
    Catch
      'Nothing to do :P
    End Try
   End If
The first time I read FindLocation I can read my own location ("Madonna del passo", that's a tiny district in Rieti), worldweather doesn't return an AreaName because, i guess, my own location is too specific to be found. If, then, I use meteo.cityname writing an actual city into the edtLoc edit (let's say I write Rome in it) it does return the correct meteo data. If then I use again the FindLocation feature, I get FindLocation to be "Madonna del Passo" but AreaName still remains on "Rome" returning wrong meteo data. Is this a bug or am I using it in a wrong way?

Grazie.
Raffaele
 

lonleystar

Well-Known Member
Licensed User
Longtime User
2 weeks ago I bought a new computer an Intel Core I7 4470k MB Asus z87-16 GB ram - SSD 128 GB HDD 1 TB everything seemed to work fine, but just SSD and HHD have reported many errors of sectors, have sent them back and I am waiting. For this I´m not in the forum now I am answering with my girlfriend's laptop. but thanks to have reported this error as soon as possible i´ll check it.
 

FreeWolF

Active Member
Licensed User
Longtime User
Yea!! I have a question:

I have wrote that code:

I can't understand how to put ONLY the description of the future weater in a edittext.

For example:

B4X:
Dim a As ICOSWorldForecast    

Activity.LoadLayout("Main")

    a.Initialize("a")   
    a.ApiKey="My API key (free)"
    mCityname = "Rome"
    a.CityName = mCityname

EditText1.Text = a.CCWeatherDescription

With that code I can see the PRESENT weater condition, but if I want to see the condition for tomorrow in an another Edittext, how can I do it?

I repeat: I want only the description, I don't need the Icon :)

Thanks in advance!!
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
a.ccxxxxxxxxx = current conditions
a.fcxxxxxxxxx = forcast conditions and is an array

so look at properties that start with fc
 

FreeWolF

Active Member
Licensed User
Longtime User
Thanks a lot to all for the quick reply!!!

I have wrote the following code:

B4X:
Sub Globals
Dim meteo As ICOSWorldForecast
   
   Private EditText1 As EditText
   Private EditText2 As EditText
   Private EditText3 As EditText
   Private EditText4 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)

   Activity.LoadLayout("Main")
   
   meteo.Initialize("meteo")
   meteo.CityName = "Carpi"
     
   meteo.ApiKey = "My Weather Key FREE"
   
   EditText1.text = meteo.Short7DayName(0) & " " & meteo.FCDate(0) & " " & meteo.FCWeatherDesc(0)
   EditText2.Text = meteo.Short7DayName(1) & " " & meteo.FCDate(1) & " " & meteo.FCWeatherDesc(1)
   EditText3.Text = meteo.Short7DayName(2) & " " & meteo.FCDate(2) & " " & meteo.FCWeatherDesc(2)
   EditText4.Text = meteo.Short7DayName(3) & " " & meteo.FCDate(3) & " " & meteo.FCWeatherDesc(3)
   
   
End Sub

With that code I receive the following error:

An error has occured in sub: java.lang. NullPointerException: Error Parsing Weather!!! Continue?

Why I receive that error ? Where is the mistake??

I had tried to change the city to another (New York), but the error is always the same......
 

Laurent95

Active Member
Licensed User
Longtime User
Thanks a lot to all for the quick reply!!!

I have wrote the following code:

B4X:
Sub Globals
Dim meteo As ICOSWorldForecast  .../...
    
   meteo.Initialize("meteo")  
   meteo.CityName = "Carpi"    <-- This must be after you put your personal key
   
   meteo.ApiKey = "My Weather Key FREE"    <-- Before the city
 
.../....
End Sub

Hello,

In first, put your initialisation of the Library with your key before send the city (see the comments in quote).
You catch this error if the Library isn't initialized with an allowed key before that the city was sent.

And after some tip below :

Test if Internet is on.
This Library can return an Error Code who is not totaly related with the context because the latence of the request on Website.
Also put your request in a part of Try/Catch code you can know if your request had results.
The better way before use the results is to make some tests like that :

B4X:
Sub Globals
Dim meteo As ICOSWorldForecast  .../...
    
   meteo.Initialize("meteo")  
   meteo.ApiKey = "My Weather Key FREE"

   If meteo.isWiFiConnected = True Then
        meteo.CityName = "Carpi"

        Try
             Log("now weather AreaName is " & weather.AreaName)
             'Or whatever you want test and you're sure that isn't already filled.
             'This line of print log will return an error if the library cannot return the forecast data.

             EditText1.text = meteo.Short7DayName(0) & "" & meteo.FCDate(0) & "" & meteo.FCWeatherDesc(0)
             EditText2.Text = meteo.Short7DayName(1) & "" & meteo.FCDate(1) & "" & meteo.FCWeatherDesc(1)
             EditText3.Text = meteo.Short7DayName(2) & "" & meteo.FCDate(2) & "" & meteo.FCWeatherDesc(2)
             EditText4.Text = meteo.Short7DayName(3) & "" & meteo.FCDate(3) & "" & meteo.FCWeatherDesc(3)
       Catch
             Log("no weather data returned")
        End Try
    Else
        Log("seems Wifi not work")
    End if
End Sub

Hope that it can help you.

Regards.
 

Laurent95

Active Member
Licensed User
Longtime User
To Giuseppe Salvi, a suggestion.

Hi Giuseppe,

Hope that your computer feels better soon :)

It will be possible to have the return of an error code if library haven't the weather's datas from Website in a future version ?
I know there are Error codes in return if there are an issue.
Often it's the cause of issues in our developments.

Thanks in advance if it's possible and if that don't take so much of your time, that will be :cool:.

Best regards.
Laurent.
 

Laurent95

Active Member
Licensed User
Longtime User
Ciao Giuseppe,
I'm trying to use the FindLocation and AreaName feature to find the actual position of the user.
.../...

The first time I read FindLocation I can read my own location ("Madonna del passo", that's a tiny district in Rieti), worldweather doesn't return an AreaName because, i guess, my own location is too specific to be found.
If, then, I use meteo.cityname writing an actual city into the edtLoc edit (let's say I write Rome in it) it does return the correct meteo data.
If then I use again the FindLocation feature, I get FindLocation to be "Madonna del Passo" but AreaName still remains on "Rome" returning wrong meteo data.
Is this a bug or am I using it in a wrong way?

Grazie.
Raffaele

Ciao Raffaele,

I don' t know, if you have found the response but as i'm here :)
No you don't do any mistake, that's only because the library don't empty the fields before the data are updated i think.
I was had this issue sometime, you must test data before.
Or put them in a database like me that allow you to reset all before.

Emmmmm, maybe be it will be another request at Giuseppe to reset datas before.
Poor guy, Giuseppe hasn't computer for now, and the groceries list grow up (Joke ;))

Regards.
Laurent.
 

FreeWolF

Active Member
Licensed User
Longtime User
Hello,

In first, put your initialisation of the Library with your key before send the city (see the comments in quote).
You catch this error if the Library isn't initialized with an allowed key before that the city was sent.

And after some tip below :

Test if Internet is on.
This Library can return an Error Code who is not totaly related with the context because the latence of the request on Website.
Also put your request in a part of Try/Catch code you can know if your request had results.
The better way before use the results is to make some tests like that :

B4X:
Sub Globals
Dim meteo As ICOSWorldForecast  .../...
   
   meteo.Initialize("meteo") 
   meteo.ApiKey = "My Weather Key FREE"

   If meteo.isWiFiConnected = True Then
        meteo.CityName = "Carpi"

        Try
             Log("now weather AreaName is " & weather.AreaName)
             'Or whatever you want test and you're sure that isn't already filled.
             'This line of print log will return an error if the library cannot return the forecast data.

             EditText1.text = meteo.Short7DayName(0) & "" & meteo.FCDate(0) & "" & meteo.FCWeatherDesc(0)
             EditText2.Text = meteo.Short7DayName(1) & "" & meteo.FCDate(1) & "" & meteo.FCWeatherDesc(1)
             EditText3.Text = meteo.Short7DayName(2) & "" & meteo.FCDate(2) & "" & meteo.FCWeatherDesc(2)
             EditText4.Text = meteo.Short7DayName(3) & "" & meteo.FCDate(3) & "" & meteo.FCWeatherDesc(3)
       Catch
             Log("no weather data returned")
        End Try
    Else
        Log("seems Wifi not work")
    End if
End Sub

Hope that it can help you.

Regards.


Thanks a lot! Now is working fine!!
 

Laurent95

Active Member
Licensed User
Longtime User
Thanks a lot! Now is working fine!!
You're welcome.

P.S. : A precision, the library of Giuseppe don't returns Error code like i told it before. It's why Android generates an error code who isn't related to the usage of the library, but more to the code's line who is executed. It's why it's sometime difficult to understand the mistake. Anyway, this library stay very good and useful.
 
Top