GPSの研究 その22
3851 ワード
概要
GPSを理解したかった。
android2.1でGPSロガー作って見た。
写真
サンプルコード
sdcardに、log.txtが出来る。
package com.ohisamallc.ohiapo9;
import android.app.Activity;
import android.location.GpsStatus;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TextView;
import android.view.ViewGroup;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.Context;
import android.text.format.DateFormat;
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import android.os.Environment;
public class ohiapo9 extends Activity
{
private LocationManager mLocationManager;
private LocationListener mLocationListener;
private TextView textView;
private File aFile;
private FileOutputStream out;
@Override public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setWidth(200);
textView.setText("ok");
TableLayout tableLayout = new TableLayout(this);
tableLayout.addView(textView, new TableLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
setContentView(tableLayout);
aFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/log.txt");
try
{
out = new FileOutputStream(aFile);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
@Override protected void onDestroy()
{
super.onDestroy();
mLocationManager.removeUpdates(mLocationListener);
}
@Override public void onStart()
{
super.onStart();
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
}
mLocationListener = new locationListener();
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 5, mLocationListener);
mLocationManager.addNmeaListener(nmeaListener);
}
private final GpsStatus.NmeaListener nmeaListener = new GpsStatus.NmeaListener()
{
public void onNmeaReceived(long timestamp, String nmea)
{
String s = nmea + textView.getText().toString();
textView.setText(s);
try
{
out.write(nmea.getBytes());
}
catch (IOException e)
{
e.printStackTrace();
}
}
};
private class locationListener implements LocationListener
{
public void onLocationChanged(Location loc)
{
}
public void onProviderDisabled(String arg0)
{
}
public void onProviderEnabled(String provider)
{
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
}
以上。
Author And Source
この問題について(GPSの研究 その22), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/49fadcaf137b15b7904a著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .