如何获取当前位置在区间的每1分钟? [英] How to fetch the Current Location in Every 1 min of Interval?

查看:111
本文介绍了如何获取当前位置在区间的每1分钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了演示,显示当前的经纬度长的用户的。 现在我能看到LAT-长的当前位置。 但我想将它设置为显示在区间的每1分钟。 在code是如下图:

 公共类MainActivity延伸活动{
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
LocationManager LM =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener的lListener =新mylocationlistener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,lListener);
}

私有类mylocationlistener实现LocationListener的{
    @覆盖
    公共无效onLocationChanged(位置定位){
        如果(位置!= NULL){
        Log.d(位置发生改变,location.getLatitude()+);
        Log.d(位置发生改变,location.getLongitude()+);
        Toast.makeText(MainActivity.this,
            我现在的位置:\ nLatitude:+ location.getLatitude()+\ nLogitude:+ location.getLongitude(),Toast.LENGTH_LONG).show();
        }
    }

    @覆盖
    公共无效onProviderDisabled(字符串提供商){
        // TODO自动生成方法存根

    }

    @覆盖
    公共无效onProviderEnabled(字符串提供商){
        // TODO自动生成方法存根

    }

    @覆盖
    公共无效onStatusChanged(字符串商,INT地位,捆绑演员){
        // TODO自动生成方法存根

    }

}
 

}

所以,我应该怎么需要做的,使其显示当前的经纬度,长间隔的每个1分钟? 我想我必须使用线程来实现它。但是,任何人都可以帮助我,code怎么可能? 先谢谢了。

解决方案

  lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,lListener);
 

在该方法的参数表示 - 提供商,时间,距离和位置监听

因此​​,从位置监听器,你需要设置第二个参数为1000 * 60,因为时间被记录在毫秒为单位请求更新。

I have implemented the Demo to Show the Current lat-long of the User. Now i am able to see the lat-long of the Current Position. but i want to Set it to to be displayed in every 1 min of interval. The Code is as Below:

public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener lListener = new mylocationlistener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, lListener);
}

private class mylocationlistener implements LocationListener {
    @Override
    public void onLocationChanged(Location location) {
        if (location != null) {
        Log.d("LOCATION CHANGED", location.getLatitude() + "");
        Log.d("LOCATION CHANGED", location.getLongitude() + "");
        Toast.makeText(MainActivity.this,
            "My Current location:\nLatitude:"+location.getLatitude() + "\nLogitude:" + location.getLongitude(),Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

}

}

So, What should i have to do to make it to display the current lat-long in every 1 min of interval ?? I think i have to use the thread to implement it. But can anyone help me by code to how to make it possible ? Thanks in advance.

解决方案

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, lListener);

The argument in the method signify - provider, time, distance and the location listener.

Therefore to request an update from the Location listener you need to set the second parameter to 1000*60, because the time is recorded in milliseconds.

这篇关于如何获取当前位置在区间的每1分钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆