我正在使用塔ID和gps获取gps位置我可以获取当前位置并在吐司中显示它我必须每隔五分钟自动发布它并且还要在android设备上的地图中显示它可以任何人帮我。我的代码是
public void onClick(View arg0) {
// create class object
gps = new GPSTracker(AndroidGPSTrackingActivity.this);
// check if GPS enabled
if(gps.canGetLocation()){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
// \n is for new line
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(),"cant get location", 1000 ).show();
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
gps.showSettingsAlert();
}
}
答案 0 :(得分:0)
查看LocationManager.requestLocationUpdates。它会在位置提供程序更新时自动更新。您可以在该API中将其最大频率设置为5分钟。
答案 1 :(得分:0)
thread1=new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
while (true) {
try {
Thread.sleep(1000*60*5);
mHandler.post(new Runnable() {
public void run() {
// TODO Auto-generated method stub
// Write your code here to update the UI.
});
} catch (Exception e) {
// TODO: handle exception
}
}
}
});