android中的GPS记录器
我需要一个与GPS记录器工作的帮助。我有一个开关按钮。在我设置它的地方,我需要启动GPS记录器,我需要设置记录器间隔。我需要在sqlite数据库中显示纬度和经度,并根据日志间隔更新数据库 任何工作示例代码都将对我有所帮助。我找到了许多应用程序示例。但是没有起作用。任何示例工作链接都将非常有帮助android中的GPS记录器,android,gps,Android,Gps,我需要一个与GPS记录器工作的帮助。我有一个开关按钮。在我设置它的地方,我需要启动GPS记录器,我需要设置记录器间隔。我需要在sqlite数据库中显示纬度和经度,并根据日志间隔更新数据库 任何工作示例代码都将对我有所帮助。我找到了许多应用程序示例。但是没有起作用。任何示例工作链接都将非常有帮助 public class LocalisationService extends Service { private LocationManager locationManager; pr
public class LocalisationService extends Service
{
private LocationManager locationManager;
private BroadcastReceiver receiver;
//Define a listener that responds to location updates
private LocationListener locationListener = new LocationListener()
{
//Called when a new location is found by the network location provider
public void onLocationChanged(Location location)
{
//insertion of the location in the DB
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
@Override
public IBinder onBind(Intent intent){return null;}
@Override
public void onCreate()
{
super.onCreate();
int interval = 1; //Specify the update interval
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, locationListener);
IntentFilter filter = new IntentFilter();
filter.addAction("STOP_LOCALISATION_SERVICE");
receiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
stopSelf();
}
};
registerReceiver(receiver, filter);
}
@Override
public void onDestroy()
{
unregisterReceiver(receiver);
locationManager.removeUpdates(locationListener);
super.onDestroy();
}
}