- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
没有 gps,我无法获得天气信息。查找我的位置和天气的代码是这样的:
private boolean isRuntimePostGingerbread() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}
public void loadWeathercard() {
//Set the date
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
citylb = (TextView) findViewById(R.id.citybox);
//Check if the custom weather place preference is enabled
if (!sharedPrefs.getBoolean("weather_customlocationcheck", false)) {
citylb.setText(getString(R.string.rilevamento));
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
/**
* Check the provider exists before registering for updates from it
* */
if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER))
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 0, this);
if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER))
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, this);
locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
} else {
//Get the custom city, refresh the city label and get the weather
citylb.setText(sharedPrefs.getString("weather_customlocation", getString(R.string.location_null)));
getWeather((String) citylb.getText());
}
}
/**
* Function to check if the device is online
*/
/**
* Default method
*/
public Boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni != null && ni.isConnected()){
return true;
// This is method suggested.. Have i use this?
}
return false;
}
private void getWeather(String location) {
if (isOnline()) {
Log.d("YWeatherGetter4a", "onCreate");
YahooWeatherUtils yahooWeatherUtils = YahooWeatherUtils.getInstance();
yahooWeatherUtils.queryYahooWeather(getApplicationContext(), location, this); // Basta mettere la location presa dalle preferences
} else
Toast.makeText(getApplicationContext(), "Sorry, no connection available", Toast.LENGTH_SHORT).show();
}
/**
* Rilevo la posizione attuale
* */
public void gotWeatherInfo(final WeatherInfo weatherInfo) {
if (weatherInfo != null) {
current = weatherInfo.getCurrentText().toString();
// Converto in stringa la temperatura
TempCurrent = String.valueOf(weatherInfo.getCurrentTempC());
String TempHigh = String.valueOf(weatherInfo.getForecast1TempHighC());
String TempLow = String.valueOf(weatherInfo.getForecast1TempLowC());
// + weatherInfo.getAtmosphereHumidity() + "%" per l'umidit
/* LoadWebImagesTask task = new LoadWebImagesTask();
task.execute(
weatherInfo.getCurrentConditionIconURL()
);*/
Time oggi = new Time(Time.getCurrentTimezone());
oggi.setToNow();
String orariometeo = oggi.format("%k:%M");
ImageView imgView = (ImageView)findViewById(R.id.imageview_forecast_info);
if(current.toLowerCase().contains("sunny")){
current = getResources().getString(R.string.sunny);
Drawable myDrawable = getResources().getDrawable(R.drawable.sunny);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("partly cloudy")) {
current = getResources().getString(R.string.partlycloudy);
Drawable myDrawable = getResources().getDrawable(R.drawable.partlycloudy);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("mostly cloudy")) {
current = getResources().getString(R.string.cloudy);
Drawable myDrawable = getResources().getDrawable(R.drawable.mostlycloudy);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("fair")) {
current = getResources().getString(R.string.fair);
Drawable myDrawable = getResources().getDrawable(R.drawable.clear);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("showers")) {
current = getResources().getString(R.string.showers);
Drawable myDrawable = getResources().getDrawable(R.drawable.rain);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("foggy")) {
current = getResources().getString(R.string.foggy);
Drawable myDrawable = getResources().getDrawable(R.drawable.mist);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("thunderstorms")) {
current = getResources().getString(R.string.thunderstorms);
Drawable myDrawable = getResources().getDrawable(R.drawable.thunderstorm);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("thundershowers")) {
current = getResources().getString(R.string.thundershowers);
Drawable myDrawable = getResources().getDrawable(R.drawable.storm);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("freezingdrizzle") || current.toLowerCase().contains("hail")) {
current = getResources().getString(R.string.freezingdrizzle);
Drawable myDrawable = getResources().getDrawable(R.drawable.freezingdrizzle);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("lightsnowshowers")) {
current = getResources().getString(R.string.lightsnowshowers);
Drawable myDrawable = getResources().getDrawable(R.drawable.chanceofsnow);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("clear") || current.toLowerCase().contains("hot")) {
current = getResources().getString(R.string.clear);
Drawable myDrawable = getResources().getDrawable(R.drawable.clear);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("cloudy")) {
current = getResources().getString(R.string.cloudy);
Drawable myDrawable = getResources().getDrawable(R.drawable.cloudy);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("snow")) {
current = getResources().getString(R.string.snow);
Drawable myDrawable = getResources().getDrawable(R.drawable.snow);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("drizzle")) {
current = getResources().getString(R.string.drizzle);
Drawable myDrawable = getResources().getDrawable(R.drawable.lightrain);
imgView.setImageDrawable(myDrawable);
} else if (current.toLowerCase().contains("rain") || current.toLowerCase().contains("showers")) {
current = getResources().getString(R.string.showers);
Drawable myDrawable = getResources().getDrawable(R.drawable.rain);
imgView.setImageDrawable(myDrawable);
}
temperaturenow = (TextView) findViewById(R.id.temperaturenow);
temperaturenow.setText(current + " ");
temperatura = (TextView)findViewById(R.id.temperatura);
temperatura.setText(TempCurrent + "°");
maxmin = (TextView)findViewById(R.id.maxmin);
maxmin.setText(Html.fromHtml(TempHigh + "/" +"<small>"+TempLow+"</small>" +"°C"));
imgView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
boolean installed = appInstalledOrNot("com.yahoo.mobile.client.android.weather");
if(installed) {
String meteoinfo = weatherInfo.getWeatherurl();
//This intent will help you to launch if the package is already installed
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.yahoo.mobile.client.android.weather");
LaunchIntent.putExtra(SearchManager.QUERY, meteoinfo);
startActivity(LaunchIntent);
} else {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(weatherInfo.getWeatherurl()));
startActivity(i);
}
}
});
} else {
Toast.makeText(getApplicationContext(), "Sorry, no result returned", Toast.LENGTH_SHORT).show();
}
}
class LoadWebImagesTask extends AsyncTask<String, Void, Bitmap[]> {
@Override
protected Bitmap[] doInBackground(String... params) {
Bitmap[] res = new Bitmap[6];
res[0] = ImageUtils.getBitmapFromWeb(params[0]);
return res;
}
@Override
protected void onPostExecute(Bitmap[] results) {
super.onPostExecute(results);
citylb.setCompoundDrawablesWithIntrinsicBounds(null, null, null, new BitmapDrawable(getResources(), results[0]));
}
}
public void loadWeathercard1() {
//Set the date
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
citylbpref = (TextView) findViewById(R.id.cityboxpref);
//Check if the custom weather place preference is enabled
//Get the custom city, refresh the city label and get the weather
citylbpref.setText(sharedPrefs.getString("weather_customlocation", getString(R.string.location_null)));
getWeather1((String) citylbpref.getText());
}
@Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
List<Address> addresses = null;
if (arg0 != null){
double longitude = arg0.getLongitude();
double latitude = arg0.getLatitude();
Geocoder gcd = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
addresses = gcd.getFromLocation(latitude, longitude, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("MyTag", "MyMessage", e); // use this instead e.printStackTrace();
}
if(addresses != null && addresses.size() > 0){
citylb.setText(addresses.get(0).getLocality());
getWeather((String) citylb.getText());
}else{
citylb.setText(getString(R.string.location_null));
}
//citylb = (TextView) findViewById(R.id.citybox);
//if (addresses.size() > 0) return addresses.get(0).getLocality();
}
}
现在,我需要它有一个“手动”位置。我试图在这里更改“位置”:
yahooWeatherUtils.queryYahooWeather(getApplicationContext(), location, this);
使用像这样的字符串:
yahooWeatherUtils.queryYahooWeather(getApplicationContext(), "New York", this);
但不起作用...有什么想法吗?
最佳答案
搜索 YahooWeatherUtils,我找到了 http://www.codota.com/android/scenarios/52fcbdbbda0ae4ff7532748f/com.google.android.gms.location.LocationClient?tag=dragonfly
他们的建议是:
Location location = locationClient.getLastLocation();
YahooWeatherUtils ywu = YahooWeatherUtils.getInstance();
if PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("weatherUseCurrentLocation", true) && location != null) {
ywu.queryYahooWeather(getActivity(), location , this);
} else {
String city = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("weatherCity", "Vancouver Canada");
ywu.queryYahooWeather(getActivity(), city , this);
}
所以,函数queryYahooWeather
似乎可以获取纬度/经度或城市名称。您只需要足够的城市名称信息。
关于java - 在没有 gps 的情况下获取天气信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23067587/
我有一个 GSM/GPS 单元连接到一个微 Controller ,它们之间的通信工作正常。我能够获取 GPS 并将其发送到微 Controller ,但有时设备在建筑物内,所以我无法真正获取当前的
它显示,错误指出“没有符合条件的应用安装设备” 设备规范如下, 型号:联想A369i Android 操作系统版本:4.2.2 我在 android mainfest 文件中执行以下权限
我有一个 Adafruit FONA 3G/GPS 模块 ( American Version )。我已经可以使用蜂窝功能,但 GPS 功能却遇到了困难。我尝试过无源和有源天线。 这是 SIM5320
今天在将我的应用程序上传到市场时,我发现它仅适用于具有 GPS 的设备,因此不包括某些平板电脑。 我的应用程序中的 GPS 是可选的。是否可以为有和没有 GPS 的设备发布一个应用程序,或者我需要制作
在 Monodroid 中,我正在尝试访问 GPS 服务。我只需要一个位置对象。 这一行报错: _locationManager.RequestLocationUpdates(LocationMana
我是 GPS 世界的新手。我需要知道如何使用 DGPS 进行后处理。我在网上找到了关于 DGPS、后处理等的定义,但是,找不到关于如何实际进行 DGPS 后处理的明确步骤。在搜索提供商时,我发现 CO
我有一系列 gps 值,每个值包含:timestamp, latitude, longitude, n_sats, gps_speed, gps_direction, ... ( NMEA data
抱歉,如果这是错误的“堆栈”。我找不到更合适的。 我为我的狗买了一个 GPS 追踪器,它附带订阅、一张 SIM 卡和一个开发不佳的应用程序。 我已取消订阅并想使用该设备将位置信息发送到我自己的服务器。
有没有一种在线方法可以用来获取 Google map 上两点之间路线上的所有 gps 点?即,如果我给出起点和终点,我需要获取该特定路线上的所有 GPS 点。 最佳答案 除了数据的所有者之外,每个人都
我正在尝试从 GPS 跟踪设备转换 GPS 数据。该公司提供了协议(protocol)手册,但不清楚。我能够从我从设备收到的数据包中解码的大部分数据。通信是通过 TCP/IP 进行的。我在解码经度和纬
我想从 GPS 坐标中获取城市名称。我可以使用 Google API 获取 GPS 点的详细信息 http://maps.googleapis.com/maps/api/geocode/output?
我做了一个 .gpx 文件来模拟 IOS 模拟器上的路线,现在我想模拟水平精度我该怎么做? 以下是我的 .gpx 文件的摘录: //how add horizontal accuracy
我有两个 GPS 坐标 例如(Lat1, Long1) 和 (Lat2,Long2) 谁能帮我找到这两点之间的角度。 值应为 0-360 度。 最佳答案 取自 this以前的SO帖子: float d
我正在为一个小类项目寻找 GPS。我们想要尽可能小的 GPS,我们真正需要它做的就是在我们轮询时为我们提供经度和纬度值。 我尝试查看 sparkfun,但由于我们之前没有真正使用过这种类型的硬件,因此
我正在处理 GPS 数据,每秒获取值并在 map 上显示当前位置。问题在于,有时(特别是当精度较低时)这些值变化很大,使得当前位置在 map 中的远距离点之间“跳跃”。 我想知道一些足够简单的方法来避
我正在创建一个请求用户位置的 BREW 应用程序。 如果手机无法获取位置,我想显示错误。 在确定手机不太可能获得 GPS 定位之前,我应该等待回调多久? 最佳答案 当需要冷启动时,接收器必须下载全套星
我有一辆安装了跟踪器的车辆。该设备具有 GPS 系统、3 轴加速度计、3 轴磁力计和陀螺仪。是否可以通过车辆在斜坡或山坡上向后滚动的程度来确定。使用 gps 角度不是一种选择,因为为短距离向后移动提供
我们计划编写一个软件,每 5 秒左右跟踪一次汽车的 GPS 位置、GPS 信号强度、加速度计(X、Y、Z)和陀螺仪(X、Y、Z)。并将数据发送到服务器进行后期处理。服务器将确定哪些道路上有汽车。所以这
这是我的问题:智能手机会向我的服务器发送一些 gps 坐标(纬度、经度、高度),我必须将这些坐标与存储在数据库中的地址进行比较,以查看智能手机和服务器之间的距离地址。为了进行实际比较,我还需要获取此地
HTML5 浏览器可以检索计算机的 gps 位置。 http://diveintohtml5.ep.io/geolocation.html 我想创建一个伪造 GPS 设备的应用程序,但我无法在任何地方
我是一名优秀的程序员,十分优秀!