GPS 연구 22
3717 단어 GPS 로거android2.1GPS
개요
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)
{
}
}
}
이상.
Reference
이 문제에 관하여(GPS 연구 22), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ohisama@github/items/49fadcaf137b15b7904a
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
샘플 코드
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)
{
}
}
}
이상.
Reference
이 문제에 관하여(GPS 연구 22), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ohisama@github/items/49fadcaf137b15b7904a
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
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)
{
}
}
}
Reference
이 문제에 관하여(GPS 연구 22), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ohisama@github/items/49fadcaf137b15b7904a텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)