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
Hi Laurent, u r right I'm so sorry about this inconvenience but did u tried my demo? it work to u.
:) No worries Giuseppe it's me who had does a mistake.
That teach me that we must pay attention to survey all changes between two versions.
It's not to you to ask forgiveness already you work for us.

Yes your example work fine and it's from it that i discover my mistake.
Now both work fine, your and mine :)

Grazie Giuseppe.

Ciao.
 

MarcoRome

Expert
Licensed User
Longtime User
Hi Giuseppe, i have this problem:

B4X:
a.Initialize("a")  
    a.ApiKey="m7sutqf7uXXXXXXXX"
    Activity.LoadLayout("1")
    a.Initialize("a")
    lat = a.Latitude
    lon = a.Longitude
    a.LatAndLong = lat & "," & lon
    citta = a.FindLocation

give me error... or for better explain return citta empty.
if i add this code i haven't problem:

B4X:
a.Initialize("a")  
    a.ApiKey="m7sutqf7uxdbr6XXXXXXXXXXX"
    Activity.LoadLayout("1")
    a.Initialize("a")
    a.CityName="rome"
    lat = a.Latitude
    lon = a.Longitude
    a.LatAndLong = lat & "," & lon
    citta = a.FindLocation


WhY ?
i want give my city with gps ( the code return coordinate right )
Thank you for all.

Italiano:
Ciao Giuseppe ho questo problema:

B4X:
[CODE]a.Initialize("a")
    a.ApiKey="m7sutqf7uXXXXXXXX"
    Activity.LoadLayout("1")
    a.Initialize("a")
    lat = a.Latitude
    lon = a.Longitude
    a.LatAndLong = lat & "," & lon
    citta = a.FindLocation
[/CODE]

Questo codice torna errore dandomi lat come errore, differentemente se aggiungo prima la linea " a.CityName="rome" " è ok.
Ora vorrei prelevare tramite la funzione LatAndLong direttamente la posizione del tipo:

B4X:
    a.Initialize("a")  
    a.ApiKey="m7sutqf7uxdbrXXXXXXX"
    Activity.LoadLayout("1")
    a.Initialize("a")
    lat = a.Latitude
    lon = a.Longitude
    a.LatAndLong = lat & "," & lon
    citta = a.FindLocation
    ImageView1.Bitmap = a.FCIcon(0)
    Label1.Text = "Firenight " & a.CCTempFahrenheit
    Label2.Text = "Celsius " & a.CCTempCelsius & "°"
  
    ImageView2.Bitmap = a.FCIcon(1)
    Label3.Text = "Tempo domani"
    Label4.Text =  a.FindLocation

. Potresti cortesemente farmi un esempio ?
Grazie mille e ottima libreria
 
Last edited:

Laurent95

Active Member
Licensed User
Longtime User
Hi Giuseppe, i have this problem:

B4X:
a.Initialize("a")
    a.ApiKey="m7sutqf7uXXXXXXXX"
    Activity.LoadLayout("1")
    a.Initialize("a")
    lat = a.Latitude
    lon = a.Longitude
    a.LatAndLong = lat & "," & lon
    citta = a.FindLocation
.../....

Hello,

Giuseppe has already responded to this, it's necessary you test if the Website respond before.
You must have your own account on http://www.geonames.org/ and use it with declaration like, a.SetGeoUserName ="your_own_user_account".
Take a look at this message of Giuseppe, http://www.b4x.com/android/forum/threads/icosworldforecast-3-10.21852/page-17#post-247863

We discuss about several time before, even if other problem has appeared that still necessary you use your own account.
It's probably why you have an issue.
Take a look at the example attached, all things needed are inside, don't forget to put your own apiKey on WWO and your username on the geonames.org

Regards.
 

Attachments

  • ICOSWorldForecast_v3.10Demo.zip
    36.2 KB · Views: 200
Last edited:

Laurent95

Active Member
Licensed User
Longtime User
@ MarcoRome
Hi Giuseppe, i have this problem:

B4X:
a.Initialize("a")
    a.ApiKey="m7sutqf7uXXXXXXXX"
    Activity.LoadLayout("1")
    a.Initialize("a")
    lat = a.Latitude
    lon = a.Longitude
    a.LatAndLong = lat & "," & lon
    citta = a.FindLocation

give me error... or for better explain return citta empty.
if i add this code i haven't problem:

B4X:
a.Initialize("a")
    a.ApiKey="m7sutqf7uxdbr6pnwahqxywf"
    Activity.LoadLayout("1")
    a.Initialize("a")
    a.CityName="rome"
    lat = a.Latitude
    lon = a.Longitude
    a.LatAndLong = lat & "," & lon
    citta = a.FindLocation

Hello,

You're right i have read so quick last time and unfortunatly i don't use the IP adress in this example.
Seems this old function 'a.LatAndLong' don't work now, you must replace it by 'a.WeaterByLocalIpAddress=a.LocalIpAddress' .
Or 'a.WeaterByLocalIpAddress=lat & "," & lon' but you use 2 variables for nothing unless you use them after.

In your second case the Website respond because the city is iniitalized.

But my first response still correct you need to follow what Giuseppe say about the geoname user account.

Good prog.

Regards.
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Hi all.
The app work fine but in sometime give me this error:
"An error has occurred in sub: java.lang.NullPointerException: Error Parsing Weather!!!!"

Any help is appreciated.
Thanks
 

MarcoRome

Expert
Licensed User
Longtime User
Thank you for your response.
"Error Parsing Weather!!!!" i see when internet connect i lost. So i resolve with server.GetMyIP = "127.0.0.1" ....
I have one question for you
With your library, you can intercept using gps the place and pass that parameter or you must always enter a.CityName="example name city".
Thank you
 

MarcoRome

Expert
Licensed User
Longtime User
Hi Giuseppe i try a.CityName = a.FindLocation but without success:

B4X:
a.Initialize("a")

    a.ApiKey="m7sutqf7uXXXXXXXXXXXX"
    Activity.LoadLayout("1")
    a.Initialize("a")
    a.CityName = a.FindLocation
    Label1.Text = "Firenight " & a.CCTempFahrenheit
    Label2.Text = "Celsius " & a.CCTempCelsius & "°"
    ImageView1.Bitmap = a.FCIcon(0)

if i utilize a.CityName = "New York" ' or another place work without problem:

B4X:
a.Initialize("a")

    a.ApiKey="m7sutqf7uXXXXXXXXXXXX"
    Activity.LoadLayout("1")
    a.Initialize("a")
    a.CityName = "New York" ' or another place
    Label1.Text = "Firenight " & a.CCTempFahrenheit
    Label2.Text = "Celsius " & a.CCTempCelsius & "°"
    ImageView1.Bitmap = a.FCIcon(0)

what you think ?
Thank you
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi Marco, this is just a way to get the location but u can use different way.

B4X:
Sub Button1_click
If a.isWiFiConnected = True Then
    If a.FindLocation.Length > 0 Then
 
      a.CityName = a.FindLocation
      StartActivity(Forecast)

    End If
End If
End Sub

Or

Sub Button1_click
If a.isWiFiConnected = True Then
   If a.FindLocation.Length > 0 Then
     Try
      a.CityName = a.FindLocation
      StartActivity(Forecast)
     Catch
       ToastMessageShow(" Probably server error!! ",True)
     End Try
    End If
End If
End Sub
 

MarcoRome

Expert
Licensed User
Longtime User
Hi Giuseppe i already try this way . The internet connection work ( infact if you put in a.City = "name city" work very well and show me temperature ico ..etc. ) i think that is a.Findlocation taht have problem because is null as value.
I use Library ICOSWorldForecast 2.84.
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi Marco, did u tried the first option? let me know.


B4X:
Sub Button1_click
If a.isWiFiConnected = True Then
    If a.FindLocation.Length > 0 Then
      a.CityName = a.FindLocation
      StartActivity(Forecast)

    End If
End If
End Sub

P.S.

I'll implement a broadcast receive as soon as i finish the new GridView.



Which kind of program u use to record the video.
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Yes Giuseppe but as you see in movie in the findlocation.Length is null and so jump .... i use for movie camtasia studio 8.
it is possibile get sCityNames, because there is correct value.
this is my email info@queenandroid.com
Thank you again
 
Top