GPSの研究 その18
2732 ワード
概要
GPSを理解したかった。
android2.1で、NMEAを眺めるだけのアプリ。
写真
サンプルコード
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;
public class ohiapo9 extends Activity
{
private LocationManager mLocationManager;
private LocationListener mLocationListener;
private TextView textView;
@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);
}
@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);
}
};
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)
{
}
}
}
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;
public class ohiapo9 extends Activity
{
private LocationManager mLocationManager;
private LocationListener mLocationListener;
private TextView textView;
@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);
}
@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);
}
};
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の研究 その18), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/3af30a1f2102246a147a著者帰属:元の著者の情報は、元の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 .