很急,android中定位满足一定条件后后开启另一个活动 android对话框gps 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 locationmanager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);Criteria criteria=new Criteria();criteria.setAccuracy(Criteria.ACCURACY_FINE);criteria.setPowerRequirement(POWER_LOW);provider=locationmanager.getBestProvider(criteria, true);location=locationmanager.getLastKnownLocation(provider);boolean sl=updateWithNewLocation(location);locationmanager.requestLocationUpdates(provider, 1000, 0.0f, locationListener);//locationlistener已经实现过了,没贴出来handler.post(new Runnable(){public void run(){panduan(location);Log.i(tag, "弹出dialog");}});protected boolean updateWithNewLocation(Location location) {// TODO Auto-generated method stubboolean bl=false;mylocationText0=(TextView)findViewById(R.id.mylocationtext0);mylocationText1=(TextView)findViewById(R.id.mylocationtext1);mylocationText=(TextView)findViewById(R.id.mylocationtext2);mylocationText2=(TextView)findViewById(R.id.mylocationtext3);if(location!=null){double log=location.getLongitude();double lat=location.getLatitude();mylocationText0.setText("您现在处于纬度:"+lat+"\n");mylocationText1.setText("您现在处于经度:"+log+"\n");double lat_dsn=34.24970526326096;double log_dsn=108.98116439580917;double distance=getDistance(lat, log, lat_dsn, log_dsn);//double distance1=distance(x, y);mylocationText.setText("您距离目的地还有:"+distance+"米");if(isArrived(distance)){/* * 弹出一个对话框选择后加载minimap *///new Thread().start();//locationmanager.removeUpdates(locationListener);//Dialog myDialog=dialog(this);//myDialog.show();//此时停止当前线程bl=true;}else{mylocationText2.setText("您正在接近目的地");}}else{//Dialog myDialog=dialog(this);//myDialog.show();mylocationText2.setText("获取信息失败,网络未连接!"); bl=true;}return bl;}private boolean isArrived(double distance) {if((distance<50)&&(distance>20)){Toast.makeText(MapActivity.this, "您已经离目的地很近了",Toast.LENGTH_SHORT).show();return false;}if(distance<20){mylocationText2.setText("您已经到达目的地,是否进入minimap?");return true;}else{return false;}}private Dialog dialog(Context context){AlertDialog.Builder builder=new AlertDialog.Builder(context);builder.setTitle("minimap indicates");builder.setMessage("您已经到达目的地,是否进入minimap");builder.setIcon(R.drawable.ic_launcher);builder.setPositiveButton("取消",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubdialog.dismiss();}});builder.setNegativeButton("确定",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubflag=false;Intent intent=new Intent(MapActivity.this, minimapActivity.class);startActivity(intent);}});return builder.create();}public void panduan(Location location){ if(updateWithNewLocation(location)){ Dialog myDialog=dialog(this); myDialog.show(); Log.i(tag, "出现了吧dialog?"); } }让别人帮你看,你带也贴规范点儿啊,这一大坨的。目测应该是下面这段代码在反复执行,这段代码是怎么调用的?handler.post(new Runnable(){public void run(){panduan(location);Log.i(tag, "弹出dialog");}}); 多谢四楼 后来我是这样解决的 本人才学半个月 比较菜 见谅 下次贴代码用notepad贴 android项目访问E盘上的图片 求助!提醒功能的实现(service,broadcast,alarmmanage) Unable to resolve target 'android-9' 一个Activity中如何显示2个View 求救:如何获取图片的分辨率 求irrlicht的android版本 layout布局,怎样布局后呈现圆形? popupwindow 中加listview,点击item时popupwindow不消失的问题?? 新手求救,关于android内容提供者 Android Socket求解 视频乱码怎么回事 怎么直接调用系统设置好的闹钟(自己解决了,来几个收分的)
Criteria criteria=new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(POWER_LOW);
provider=locationmanager.getBestProvider(criteria, true);
location=locationmanager.getLastKnownLocation(provider);
boolean sl=updateWithNewLocation(location);
locationmanager.requestLocationUpdates(provider, 1000, 0.0f, locationListener);//locationlistener已经实现过了,没贴出来
handler.post(new Runnable(){
public void run(){
panduan(location);
Log.i(tag, "弹出dialog");
}
});
protected boolean updateWithNewLocation(Location location) {
// TODO Auto-generated method stub
boolean bl=false;
mylocationText0=(TextView)findViewById(R.id.mylocationtext0);
mylocationText1=(TextView)findViewById(R.id.mylocationtext1);
mylocationText=(TextView)findViewById(R.id.mylocationtext2);
mylocationText2=(TextView)findViewById(R.id.mylocationtext3);
if(location!=null){
double log=location.getLongitude();
double lat=location.getLatitude();
mylocationText0.setText("您现在处于纬度:"+lat+"\n");
mylocationText1.setText("您现在处于经度:"+log+"\n");
double lat_dsn=34.24970526326096;
double log_dsn=108.98116439580917;
double distance=getDistance(lat, log, lat_dsn, log_dsn);
//double distance1=distance(x, y);
mylocationText.setText("您距离目的地还有:"+distance+"米");
if(isArrived(distance)){
/*
* 弹出一个对话框选择后加载minimap
*/
//new Thread().start();
//locationmanager.removeUpdates(locationListener);
//Dialog myDialog=dialog(this);
//myDialog.show();//此时停止当前线程
bl=true;
}else{
mylocationText2.setText("您正在接近目的地");
}
}else{
//Dialog myDialog=dialog(this);
//myDialog.show();
mylocationText2.setText("获取信息失败,网络未连接!");
bl=true;
}
return bl;}
private boolean isArrived(double distance) {
if((distance<50)&&(distance>20)){
Toast.makeText(MapActivity.this, "您已经离目的地很近了",Toast.LENGTH_SHORT).show();
return false;
}if(distance<20){
mylocationText2.setText("您已经到达目的地,是否进入minimap?");
return true;
}else{
return false;
}
}
private Dialog dialog(Context context){
AlertDialog.Builder builder=new AlertDialog.Builder(context);
builder.setTitle("minimap indicates");
builder.setMessage("您已经到达目的地,是否进入minimap");
builder.setIcon(R.drawable.ic_launcher);
builder.setPositiveButton("取消",new DialogInterface.OnClickListener() {@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stubdialog.dismiss();}
});
builder.setNegativeButton("确定",new DialogInterface.OnClickListener() {@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
flag=false;
Intent intent=new Intent(MapActivity.this, minimapActivity.class);
startActivity(intent);}
});
return builder.create();
}
public void panduan(Location location){
if(updateWithNewLocation(location)){
Dialog myDialog=dialog(this);
myDialog.show();
Log.i(tag, "出现了吧dialog?");
}
}让别人帮你看,你带也贴规范点儿啊,这一大坨的。目测应该是下面这段代码在反复执行,这段代码是怎么调用的?
handler.post(new Runnable(){
public void run(){
panduan(location);
Log.i(tag, "弹出dialog");
}
});
本人才学半个月 比较菜 见谅 下次贴代码用notepad贴