Java Reference
In-Depth Information
}
}
}
Being that the PullParser 's member variable, input , is bound to the location-
Input variable, this code is invoked whenever the input stream is updated and
the parse method is called. This occurs when the user enters a ZIP code and
presses Return, as processed in the action function highlighted in bold typeface
in Listing 10.6. After the location data is processed, the results are used in the
request to the GeoNames service to receive the current weather conditions. Let's
take a look at this process now.
Using GeoNames Web Services
As mentioned earlier, the GeoNames service returns the current weather condi-
tions by either a supplied airport code or location (longitude and latitude). For
the weather widget, we want to make the request by location. The location data is
used with the following JavaFX URL string to form the request:
var coordURL = bind "http://ws.geonames.org/
findNearByWeatherJSON?lat={location.lat}&lng={location.long}";
Being bound to both the Location.lat and Location.lng variables, the text is
automatically updated with these values when they're changed. The request
returns detailed weather conditions that are stored in the fields of the Weather
class, shown in Listing 10.9.
Listing 10.9
The Weather Data Structure
class Weather {
public var station: String;
public var clouds: String;
public var windDirection: Integer;
public var windSpeed: Number;
public var temperature: Number;
public var dewPoint: Number;
public var humidity: Integer;
public var seaLevelPressure: Number;
public var observation: String;
}
These fields are updated when the JSON names that match are located within the
JSON text, as read by the PullParser class, weatherParser (see Listing 10.10).
 
Search WWH ::




Custom Search