zoukankan      html  css  js  c++  java
  • Delphi获取Android下GPS的NMEA 0183数据

    下面的程序,可以实现Android下获取GNSS的NMEA0183数据:

    unit utAndroidNmea;
    
    interface
    
    uses Androidapi.JNIBridge, Androidapi.JNI.App, Androidapi.NativeActivity, Androidapi.JNI.JavaTypes, Androidapi.JNI.Location;
    
    type
      TonNmeaReceived=procedure(timestamp: Int64; nmea: String) of Object;
    
      TJGpsStatus_NmeaListener = class(TJavaGenericImport<JGpsStatus_NmeaListenerClass, JGpsStatus_NmeaListener>) end;
    
      TNmeaProvider=class(TJavaLocal,JGpsStatus_NmeaListenerClass, JGpsStatus_NmeaListener)
      protected
        FLocationManager:JLocationManager;
        FOnNmeaReceived:TonNmeaReceived;
      public
        procedure onNmeaReceived(timestamp: Int64; nmea: JString); cdecl;
      public
        constructor Create;
        destructor Destroy;override;
        function Run:Boolean;
        property OnNmeaLineReceived:TOnNmeaReceived read FOnNmeaReceived write FOnNmeaReceived;
      end;
    
    
    
    implementation
    
    uses Androidapi.Helpers, Androidapi.JNI.GraphicsContentViewText,  FMX.Helpers.Android,
    FMX.Platform.Android, System.SysUtils, System.Android.Sensors;
    
    { TNmea }
    
    constructor TNmeaProvider.Create;
    begin
      inherited Create;
    end;
    
    destructor TNmeaProvider.Destroy;
    begin
      if Assigned(FLocationManager) then FLocationManager.removeNmeaListener(Self );
      inherited;
    end;
    
    procedure TNmeaProvider.onNmeaReceived(timestamp: Int64; nmea: JString); cdecl;
    begin
      if Assigned(FOnNmeaReceived) then FOnNmeaReceived(timestamp, JStringToString(nmea));
    end;
    
    
    function TNmeaProvider.Run:Boolean;
    begin
      CallInUiThread(procedure
      var
        LocationService: JObject;
      begin
        LocationService := SharedActivityContext.getSystemService(TJContext.JavaClass.LOCATION_SERVICE);
        FLocationManager := TJLocationManager.Wrap((LocationService as ILocalObject).GetObjectID);
        FLocationManager.addNmeaListener(Self);
      end);
    
    end;
    
    end.

    用法:

    在Form中添加一个TLocationSensor, 设置Active:=True;

    然后定义OnNmeaReceive方法:

    procedure TForm1.OnNmeaReceived(timestamp: int64; nmeasentence: String);
    begin
      FStream.Write(PChar(nmeasentence)^, Length(nmeasentence)*sizeof(Char));
    
    end;
  • 相关阅读:
    m-n的随机整数 包括m n
    获取url参数 hash类型
    js 数组转带空格字符串
    产生n-m的随机数组
    js 判断android、IOS
    判断是否微信浏览器
    文本左右对齐方式css
    H5微信支付流程
    H5微信授权登录流程
    H5页面 input禁止弹出键盘
  • 原文地址:https://www.cnblogs.com/hezihang/p/4481451.html
Copyright © 2011-2022 走看看