GPSの研究 その18


概要

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)
        {
        }
    }
}



以上。