Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Farouk Charkas
1,957 PointsWhy is this not working? (Location)
So I implemented a location tracking program to my weather app, but now it is not updating my display. Hmm? First, I thought it was just the location program that was messing it up, but then I manually added the latitude and longitude, it still did not update the display. I would appreciate if someone would help me. And, if someone know how to make a button link, that would be greatly appreciated! :-)
This is my code:
private void handleNewLocation(Location location) {
Log.d(TAG, location.toString());
double latitude = location.getLatitude();
double longitude = location.getLongitude();
getForecast(latitude, longitude);
android.util.Log.d(TAG, "The Main UI code is running!");
}
private void getForecast(double latitude, double longitude) {
String apiKEY = "1fc52007d735d76038460b34d37fbe16";
String forecastURL = "https://api.forecast.io/forecast/" + apiKEY +
"/" + latitude + "," + longitude;
if (isNetworkAvailable()) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(forecastURL)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
}
private void updateDisplay() {
mTemperatureLabel.setText(mCurrentWeather.getTemperature() + "°");
mTimeLabel.setText("At " + mCurrentWeather.getFormattedTime() + " it will be: ");
mHumidityValue.setText("Humidity: " + mCurrentWeather.getHumidity() + "");
mPrecipValue.setText("Precip. Chances: " + mCurrentWeather.getPrecipChance() + "");
mSummaryLabel.setText(mCurrentWeather.getSummary() + "");
}
I will add the full program on request!