dvdme / forecastio-lib-java Goto Github PK
View Code? Open in Web Editor NEWA Java library for the Forecast.io weather API.
License: Eclipse Public License 1.0
A Java library for the Forecast.io weather API.
License: Eclipse Public License 1.0
Hi!
I encountered problems when using forecast.io behind a proxy server.
In the current version there is no way to set anywhere the proxy and the system settings are not used by default...
I already forked the project and implemented a solution to this by adding the possibility to define a proxy if needed. I took care that this is truly optional...
I will soon use a pull request to show you my solution for your consideration...
KR, Franz
Hi, I was wondering if you could publish version 1.5.5
to jcenter?
http://jcenter.bintray.com/com/github/dvdme/ForecastIOLib/
It seems that 1.5.3
is the latest available one, but you mention in the README to Avoid using 1.5.3 and 1.5.4
.
Thanks!
Awesome Libary,
Please can you optimise this libary to work with android / android studio. it keep crashing the app each time i try to fetch the weather data.
Thanks
I'm using version 1.6.0 of ForecastIOLib, linked as
Dependencies{
implementation 'com.github.dvdme:ForecastIOLib:1.6.0'
}
I'm seeing error messages in my Android logs but I can't debug them further using what ForecastIO is logging.
I see:
05-07 18:05:47.151 6447 6780 W System.err: Bad Response:
I believe this is printed at ForecastIO.java:781,
System.err.println("Bad Response: " + response + "\n");
It seems that the library is only printing the last line of the error stream, and that error stream seems to be an HTML page.
If you could return a response code or the response stream to the application, it could decide whether or not to retry or let the end user address the issue in some way.
i have the following code:
ForecastIO fio = new ForecastIO(apikey);
fio.setUnits(ForecastIO.UNITS_SI);
fio.setLang(ForecastIO.LANG_ENGLISH);
fio.getForecast(9999999,8888888);
//Currently
FIOCurrently currently = new FIOCurrently(fio);
it would be really nice if there was a way to make the Currently / Hourly /Minutely e.t.c accessible from any activity. So that developers don't have to make an Api request every time they need to use the returned data on another activity.
Again, Awesome Libary.
When i add 1.5.1 or 1.5.2 it works perfectly,but when i use 1.5.3 i get the following error.
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/eclipsesource/json/JsonArray$1;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
response = scanner.useDelimiter("\Z").next();
seems to return only 1024 chars from the JSON response which therefor becomes invalid and the parser crashes.
What I have used (and works at least for me) is:
ForecastIO.java
if(connection.getResponseCode() == 400){
System.out.println("Bad Responde. Maybe an invalid location was provided.\n");
return null;
}
else {
// File file = new File(request.openStream());
// scanner = new Scanner(new FileInputStream());
// response = scanner.useDelimiter("\\Z").next();
// scanner.close();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
response = line;
}
}
catch (IOException e) {
}
finally {
if (reader != null) {
try {
reader.close();
reader = null;
} catch (IOException e) {
}
}
}
}
Hi,
I try to run this class in my Android project, but I get a ClassNotFoundError.
Tried to clean project, deleting/adding JAR in "Libs" folder, etc. Nothing work.
Here is my logcat report :
06-28 00:59:38.860: E/AndroidRuntime(30369): FATAL EXCEPTION: main
06-28 00:59:38.860: E/AndroidRuntime(30369): java.lang.NoClassDefFoundError: dme.forecastiolib.ForecastIO
06-28 00:59:38.860: E/AndroidRuntime(30369): at com.yyy.xxx.Weather.getCurr(Weather.java:18)
06-28 00:59:38.860: E/AndroidRuntime(30369): at com.yyy.xxx.Weather.getTemperature(Weather.java:27)
06-28 00:59:38.860: E/AndroidRuntime(30369): at com.yyy.xxx.screens.Infos$1$1.run(Infos.java:35)
06-28 00:59:38.860: E/AndroidRuntime(30369): at android.os.Handler.handleCallback(Handler.java:615)
06-28 00:59:38.860: E/AndroidRuntime(30369): at android.os.Handler.dispatchMessage(Handler.java:92)
06-28 00:59:38.860: E/AndroidRuntime(30369): at android.os.Looper.loop(Looper.java:137)
06-28 00:59:38.860: E/AndroidRuntime(30369): at android.app.ActivityThread.main(ActivityThread.java:4898)
06-28 00:59:38.860: E/AndroidRuntime(30369): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 00:59:38.860: E/AndroidRuntime(30369): at java.lang.reflect.Method.invoke(Method.java:511)
06-28 00:59:38.860: E/AndroidRuntime(30369): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
06-28 00:59:38.860: E/AndroidRuntime(30369): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
06-28 00:59:38.860: E/AndroidRuntime(30369): at dalvik.system.NativeStart.main(Native Method)
and my code :
import com.yyy.xxx.location.GPSTracker;
import dme.forecastiolib.FIOCurrently;
import dme.forecastiolib.ForecastIO;
import android.content.Context;
import android.util.Log;
public class Weather {
public static String WEATHER_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxx";
//public static String WEATHER_UNITS;
private FIOCurrently getCurr(Context c) {
GPSTracker gp = new GPSTracker(c);
ForecastIO fio = new ForecastIO(WEATHER_API_KEY);
fio.setUnits(ForecastIO.UNITS_AUTO);
fio.setExcludeURL("hourly,minutely");
Log.i("Weather", fio.getUnits());
fio.getForecast(String.valueOf(gp.getLatitude()), String.valueOf(gp.getLongitude()));
return new FIOCurrently(fio);
}
public Double getTemperature(Context c) {
FIOCurrently curr = getCurr(c);
return curr.get().temperature();
}
}
Regards,
J. L.
The property moonPhase it's not available in FIODataPoint
. I implemented and tested the new feature locally on my computer. May I fork the project and perform a pull request to yours?
Currently these methods only check if the object is non null, and if so, start querying it.
However if it's not null but empty this will fail. Adding a check of isEmpty will ix it
There are several getters that are expected to return a Double, but return -1d for a non-existent key. Example Java doc:
/**
How can one differentiate between a temperature of -1 and -1 temperature not found? Temperature is an obvious one, but also visibility might be negative distance. There might be others.
Returning null might work or returning a more obviously wrong value.
Thank you,
Matt
I am using this library in an Android application that I build with Maven. Would it be possible to package this library as a Maven artifact and keep it up to date in the central Maven repository?
Basically I'm trying to use LATEST and it fails. I suspect that it's due to maven 3.x removing compatibility with those.
Could you push another release?
(or explain how to solve the issue)
Also jitpack.io fails to compile latest commits: jitpack log which is because of missing imports. Solved here
java.lang.NumberFormatException: Invalid int: "10.5"
...
Both ForecastIO.offset
and ForecastIO.offsetValue
have this issue.
Obviously, this only occurs in timezones with offsets that are not integers.
Each time i run FIOLibTest it uses 2 API calls and i cant figure out why.
For instance, dataPoint.icon()
will not return partly-cloudy-day
but "partly-cloudy-day"
.
This is because of the way the void update(JsonObject dp)
method is coded.
This takes all the fields in the Json object and puts it in a map, like this: datapoint.put(dp.names().get(i), dp.get(dp.names().get(i)))
.
The problem is dp.get()
returns JsonNumber
, JsonString
, etc. depending on the type of the field, and JsonString.toString()
returns the value as Json code. And the Json representation of a String is its value enclosed by double quotes :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.