我需要Strings
从一类中获得LocationGetter.java
:
@Override
public void onLocationChanged(Location location) {
int latitute = (int) (location.getLatitude());
int longitude = (int) (location.getLongitude());
String lat = (String.valueOf(latitute));
String lon = (String.valueOf(longitude));
//latituteField.setText(String.valueOf(lat));
//longitudeField.setText(String.valueOf(lng));
}
到另一个班级ParseJSON.java
:
public String readWeatherFeed() {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://free.worldweatheronline.com/feed/weather.ashx?key=46d1ef574c094426121012&format=json&q="+lat+","+lon);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
Log.e(ParseJSON.class.toString(), "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}
所以我想在第二类的 URL 字符串中使用第一类的值 String lat, lon。
提前致谢。