【发布时间】:2014-04-22 17:55:55
【问题描述】:
我正在寻找一个简单的 android 天气应用程序,该应用程序可以以编程方式在文本视图中按位置显示度数和条件。
我找到了这个:http://www.survivingwithandroid.com/2013/05/build-weather-app-json-http-android.html?m=1
但这太复杂了。真的,我只需要来自我所在位置的两个数据。
public class MainActivity extends Activity implements LocationListener{
protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
TextView txtLat;
String lat;
String provider;
protected String latitude,longitude;
protected boolean gps_enabled,network_enabled;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtLat = (TextView) findViewById(R.id.textview1);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
txtLat = (TextView) findViewById(R.id.textview1);
txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" +
location.getLongitude());
}
@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude","disable");
}
@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude","enable");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude","status");
}
}
有没有简单的方法可以知道天气?
【问题讨论】:
-
并不复杂。我同意这些是您需要的更多信息,但 json 本身应该非常小并且不应该影响性能
-
是的,我可以删除我不会使用的内容,但该代码无论如何都不起作用..我试过但我得到了一些错误。所以,如果你知道一些快速的方法来获得这两个数据,也许只使用两种或三种方法,你能帮我看看吗?
标签: java android location android-location weather