问题描述
我有我的简单的android aplication一个问题,即使用GPS线。
I have a problem with my simple android aplication that use GPS cords.
我班MyLocationListener实现LocationListener的,并且有一个静态方法调用:
My class MyLocationListener implements LocationListener, and there is a static method call:
String strText ="My current location is: " + "Latitude = " + location.getLatitude() + " Longitude= " + location.getLongitude();
Toast.makeText(GpsModule.cont, strText, Toast.LENGTH_SHORT).show();
问题是显示此字符串。它说明,并且永远不会结束。当我preSS后退键主菜单,甚至当我关闭应用程序它不断地显示出来。任何线索?我怎样才能解决这个问题呢?
Problem is with displaying this string. It's showing up, and never ends. When I press back button for main menu and even when I close application it's showing up constantly. Any clue? How can I resolve this problem?
GpsModule类:
GpsModule Class:
public class GpsModule extends Activity {
public static Context cont;
//public static WebView position;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.gps);
cont = getApplicationContext();
//position = new WebView(cont);
//position = (WebView) findViewById(R.layout.gps);
//position.getSettings().setJavaScriptEnabled(true);
LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
LocationListener locListener = new MyLocationListener();
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
}
MyLocationListener类:
MyLocationListener class:
@SuppressLint("ShowToast")
公共类MyLocationListener实现LocationListener的{
public class MyLocationListener implements LocationListener{
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
location.getLatitude();
location.getLongitude();
String strText ="My current location is: " + "Latitude = " + location.getLatitude() + " Longitude= " + location.getLongitude();
Toast.makeText(GpsModule.cont, strText, Toast.LENGTH_SHORT).show();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText(GpsModule.cont, "GPS disabled", Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText(GpsModule.cont, "GPS enabled", Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
推荐答案
请阅读方法的文档 LocationManager.requestLocationUpdates()。
特别的参数:
minTime minimum time interval between location updates, in milliseconds.
每10秒尝试值10000。在生产中,你应该考虑比分钟更多的价值。
Try value 10'000 for every 10 sec. In production you should consider value more than mins.
这篇关于吐司不会从屏幕上消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!