總網頁瀏覽量

顯示具有 Gps-gps 標籤的文章。 顯示所有文章
顯示具有 Gps-gps 標籤的文章。 顯示所有文章

2012年4月22日 星期日

Android範例(2) GPS

package com.kent.gps;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class GpsTestActivity extends Activity implements LocationListener { 
private LocationManager mLocationManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);     
setContentView(R.layout.main);
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, this);
TextView mTextView00 = (TextView)findViewById(R.id.TextView00);  
mTextView00.setText("GPS Information");
}

@Override 
public void onResume(){
if (mLocationManager != null) {

}               
super.onResume();
}

@Override    
protected void onPause() {        
if (mLocationManager != null) {            
mLocationManager.removeUpdates((LocationListener) this);        
}                
super.onPause();    
}  

public void onLocationChanged(Location location) {        
TextView mTextView01 = (TextView)findViewById(R.id.TextView01);
TextView mTextView02 = (TextView)findViewById(R.id.TextView02);
TextView mTextView03 = (TextView)findViewById(R.id.TextView03);
TextView mTextView04 = (TextView)findViewById(R.id.TextView04);
TextView mTextView05 = (TextView)findViewById(R.id.TextView05);
TextView mTextView06 = (TextView)findViewById(R.id.TextView06);
TextView mTextView07 = (TextView)findViewById(R.id.TextView07);
mTextView01.setText("Latitude:  " + String.valueOf(location.getLatitude()));
mTextView02.setText("Longitude:  " + String.valueOf(location.getLongitude()));
mTextView03.setText("Accuracy:  " + String.valueOf(location.getAccuracy()));
mTextView04.setText("Latitude:  " + String.valueOf(location.getAltitude()));
mTextView05.setText("Time:  " + String.valueOf(location.getTime()));
mTextView06.setText("Speed:  " + String.valueOf(location.getSpeed()));
mTextView07.setText("Bearing:  " + String.valueOf(location.getBearing()));   
}

public void onProviderDisabled(String provider) {

}
public void onProviderEnabled(String provider) {

}
public void onStatusChanged(String provider, int status, Bundle extras) {

}   
}

2012年4月7日 星期六

GPS NMEA 訊息結構


GPS NMEA :NMEAGPS 的標準protocol,通常是ASCII的字串
每一段句子以”$”為起始位置,以16進位控制碼”13”,”10”為結尾,即”<CR>” ,”<LF>”
”<CR>”: Carriage Return 游標移到最左邊或歸位
”<LF>”: New Line Feed 換行
GGA, RMC, GSA, GSV,GLL, VTG

$GPRMC,053322.682,A,2502.6538,N,12121.4838,E,0.00,315.00,080905,,,A*6F  (RMC)最小導航資訊
053322.682
UTC Time : 格式是hhmmss.sss所以是5:33:22.682
A
定位狀態,有效為A,無效為V
2502.6538
緯度,格式: 度度分分.分分分分
N
北緯(北半球為N,南半球為S)
12121.4838
經度,格式: 度度度分分.分分分分
E
東經(東半球為E,西半球為W)
0.00
速度,單位海裏(knots)
315.00
方向
080905
日期,格式是ddmmyy(日日月月年年)

磁極變量,單位為度(degrees)

磁極變量方向,東或西
*6F
Checksum檢查位元


Android GPS framework


GpsLocation結構: 表示定位相關資訊
typedef struct {
    // set to sizeof(GpsLocation)
    size_t             size;
    //旗標位元
    uint16_t           flags;
    //緯度
    double          latitude;
    //經度
    double          longitude;
    //高度
    double          altitude;
    //速度
    float              speed;
    //方位
    float              bearing;
    //精準度
    float              accuracy;
    //時間戳記
    GpsUtcTime            timestamp;
} GpsLocation;


GpsStatusValue定義: 表示GPS晶片狀態
typedef uint16_t GpsStatusValue; //儲存GPS狀態 下面狀態的 0~4
#define GPS_STATUS_NONE             0
#define GPS_STATUS_SESSION_BEGIN    1//啟動導航
#define GPS_STATUS_SESSION_END      2//停止導航
#define GPS_STATUS_ENGINE_ON        3//未啟動導航
#define GPS_STATUS_ENGINE_OFF       4//電源關閉


GpsSvInfo結構: 描述衛星狀態
typedef struct {
    size_t  size;
    int       prn; //偽亂碼 即衛星編號
    float    snr;//衛星訊號
    float    elevation;//高度
    float   azimuth;//方位角
} GpsSvInfo;


GpsInterface結構: 連通上下層 為主要GPS的架構
typedef struct {
    size_t          size;
    int   (*init)( GpsCallbacks* callbacks );//初始化 並設定回調函數
    int   (*start)( void );//啟動導航
    int   (*stop)( void ); //關閉導航
    void  (*cleanup)( void );
    int   (*inject_time)(GpsUtcTime time, int64_t timeReference, int uncertainty);//插入目前時間
    int  (*inject_location)(double latitude, double longitude, float accuracy);//插入位置資訊
    void  (*delete_aiding_data)(GpsAidingData flags);//刪除輔助資訊
    int   (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence, uint32_t   
           min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);//設定位置模式
    const void* (*get_extension)(const char* name);//取得擴充介面
} GpsInterface;