【发布时间】:2015-08-25 03:32:34
【问题描述】:
大家好,我正在尝试显示用户与他们可以看到的卡片上某个位置之间的 gps 距离。问题是,我认为主线程分裂或一次做两件事。在下面的代码中,Android 在执行 if(flag) 语句中的代码时会敬酒……所以它会在不获取用户坐标的情况下敬酒 GPS 差异……我该如何做到这一点,如果(flag) 语句首先然后在 if 语句之后和之外继续敬酒?
@Override
public void onResume()
{
super.onResume();
ImagePath = getIntent().getStringExtra("imagePath");
if(ImagePath == null)
{
Toast.makeText(this,"hello everyone",Toast.LENGTH_LONG).show();
}
if(newCardAdded)
{
flag = displayGpsStatus();
if(flag)
{
editLocation.setText("Please!! move your device to" +
" see the changes in coordinates." + "\nWait..");
pb.setVisibility(View.VISIBLE);
locationListener = new MyLocationListener();//LocationListener actually physically gets your location
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
}
else
{
alertbox("Gps Status!!", "Your GPS is: OFF");
}
Global_Class.getInstance().getValue().getlatitude = place_lat;
Global_Class.getInstance().getValue().getlongitutde = place_lon;
String gps_distance = String.valueOf(gps_difference(user_lon, user_lat,place_lon,place_lat));
Toast.makeText(this, gps_distance, Toast.LENGTH_LONG).show();
}
}
【问题讨论】:
-
如果应该显示 gps_distance 的 toast 不能正常工作,它会显示什么?你怎么知道它发生在
if(flag)语句块的中间? -
所以在另一个活动中,我获取了一家餐馆的 GPS 坐标,我想为用户位置(我在这个活动中得到)和餐厅的位置(在另一个活动中)之间的距离干杯。因此,它只是在运行进度条尝试检索用户位置的同时显示餐厅位置。
标签: java android multithreading gps onresume