再回复之前,先把百度地图API的网址给你:http://developer.baidu.com/map/index.php?title=android-locsdk/guide/v4-2你在onReceiveLocation()中获取当前城市,获取成功后,开启新线程,做你剩下的任何操作呗。我最近刚用了百度api,为此还申请个百度开发者key,为了用它,好多操作啊。这是我的解决方式,供楼主参考 public class MyLocationListener implements BDLocationListener {
@Override
public void onReceiveLocation(BDLocation location) {
if (location == null) {
return;
}
params.put("reportTime", location.getTime());
//params.put("errorCode", location.getLocType()+"");
params.put("latitude", location.getLatitude()+"");
params.put("longitude", location.getLongitude()+"");
//params.put("radius", location.getRadius()+"");
if (location.getLocType() == BDLocation.TypeGpsLocation) {
//params.put("speed", location.getSpeed()+"");
//params.put("satellite", location.getSatelliteNumber()+"");
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
//params.put("addr", location.getAddrStr());
}
System.out.println("----->>> 当前时间 = "+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));
System.out.println("----->>> latitude = " + location.getLatitude());
System.out.println("----->>> longitude = " + location.getLongitude());
new Thread(runnable_submitData).start();
}
}
你的所有操作都可以写在runnable_submitData这里。即使网络数据交互,也解决了。
@Override
public void onReceiveLocation(BDLocation location) {
if (location == null) {
return;
}
params.put("reportTime", location.getTime());
//params.put("errorCode", location.getLocType()+"");
params.put("latitude", location.getLatitude()+"");
params.put("longitude", location.getLongitude()+"");
//params.put("radius", location.getRadius()+"");
if (location.getLocType() == BDLocation.TypeGpsLocation) {
//params.put("speed", location.getSpeed()+"");
//params.put("satellite", location.getSatelliteNumber()+"");
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
//params.put("addr", location.getAddrStr());
}
System.out.println("----->>> 当前时间 = "+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));
System.out.println("----->>> latitude = " + location.getLatitude());
System.out.println("----->>> longitude = " + location.getLongitude());
new Thread(runnable_submitData).start();
}
}
你的所有操作都可以写在runnable_submitData这里。即使网络数据交互,也解决了。
解决方案 »
- 100分求->如何在android手机上折线图,横轴为时间,纵轴为数字
- 编译android的单个模块出现问题
- android界面设计中的listview
- 关于setContentView和单击按钮功能冲突问题
- 在Unbutu下安装android虚拟机没有键盘
- 有关EditText中设置inputType后minLines属性无效的问题
- 在eclipse中,如何让主工程替换library工程的src文件
- 求助,大家帮忙看看
- popupWindow 弹出另一个PopupWindow出现问题
- 请教:手机APP与工控机通讯,用原生开发还是第三方平台混合开发?
- 在XMPP上做过订阅的兄弟姐妹,快到碗里来
- 新手的初级问题,匿名类如何向外传递结果的问题
因此你目前纠结的问题就是你要在进入应用首先去定位并达到看到界面后就已经有了最新的天气显示,不知道这样理解对不对。但是这样有个弊端,就是你在进入的时候存在一个发起定位请求到收到定位返回信息,并接着要做天气信息的查询和解析,然后才是显示到View上。那么这个过程耗时和异常将会是无法控制的,连接超时,数据丢包,定位错误等等都会造成程序卡在第一个环节。
所以我的建议是先初始化一个初始UI显示无效数据,同时用进度对话框做过渡另开线程去定位并监听定位返回接着获取天气信息并解析,期间如果有异常则做提示只显示初始界面,如果成功则直接刷新UI。这样应该是可以的。具体代码需要你自己来设计了。
一点点意见,你可以参考。也欢迎更多大牛指导。