【问题标题】:Simple android weather app简单的安卓天气应用
【发布时间】: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


【解决方案1】:

是的,实际上有一种更简单的获取天气的方法。它被称为 Forecast.io。您将在那里找到 api,并且将能够获取您的 api 密钥来访问天气。天气将显示为 json,并且易于阅读,因为有一个 api 可以读取它。此 api 提供每分钟的准确信息、7 天的预测和每小时的信息。我更喜欢它用于我之前制作的应用程序

【讨论】:

    猜你喜欢
    • 2014-05-05
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多