如何在iOS中访问指南针?

如何在iOS中访问指南针?,第1张

概述如何在Firemonkey中访问 iphone指南针? 这是一个howto视频: http://blogs.embarcadero.com/ao/2011/10/13/39171 完整源代码: http://cc.embarcadero.com/item/28536 和(短)文章: http://edn.embarcadero.com/article/41715 这是罗盘组件的源代码. 还没有尝试 如何在Firemonkey中访问 iphone指南针?解决方法 这是一个howto视频: http://blogs.embarcadero.com/ao/2011/10/13/39171
完整源代码: http://cc.embarcadero.com/item/28536
和(短)文章: http://edn.embarcadero.com/article/41715

这是罗盘组件的源代码.
还没有尝试过,但它应该工作.

unit Compass;{Based on Anders Ohlsson Firemonkey Compass example}{$IFDEF FPC}{$mode objfpc}{$H+}{$modeswitch objectivec1}{$ENDIF}interfaceuses  SysUtils,Classes,FMX_Types{$IFDEF FPC},iPhoneAll{$ENDIF}  ;type  TUpdateEvent = TNotifyEvent;  TiOSGPSCompass = class(TFmxObject)  private    FLatitude: Double;    FLongitude: Double;    FAltitude: Double;    Fheading: Double;    FOnUpdate: TUpdateEvent;    UpdateNeeded: Boolean;  protected    procedure SetLatitude(value: Double);    procedure SetLongitude(value: Double);    procedure SetAltitude(value: Double);    procedure Setheading(value: Double);    procedure Update;  public    constructor Create(AOwner: Classes.TComponent); overrIDe;    destructor Destroy; overrIDe;  published    property Latitude: Double read FLatitude;    property Longitude: Double read FLongitude;    property Altitude: Double read FAltitude;    property heading: Double read Fheading;    property OnUpdate: TUpdateEvent read FOnUpdate write FOnUpdate;  end;var  MyGPSCompass: TiOSGPSCompass = nil;procedure Register;implementation{$IFDEF FPC}uses  CoreLocation;{$ENDIF}{$IFDEF FPC}type  MyCLController = objcclass(NSObject)    locationManager : CLLocationManager;    procedure locationManager_dIDUpdatetoLocation_fromLocation(manager: CLLocationManager; newLocation,oldLocation: CLLocation); message 'locationManager:dIDUpdatetoLocation:fromLocation:';    procedure locationManager_dIDUpdateheading(manager: CLLocationManager; newheading: CLheading); message 'locationManager:dIDUpdateheading:';  end;var  Controller : MyCLController;{$ENDIF}{$IFDEF FPC}procedure MyCLController.locationManager_dIDUpdatetoLocation_fromLocation(manager: CLLocationManager; newLocation,oldLocation: CLLocation);begin  if Assigned(MyGPSCompass) then begin    MyGPSCompass.SetLatitude(newLocation.coordinate.latitude);    MyGPSCompass.SetLongitude(newLocation.coordinate.longitude);    MyGPSCompass.SetAltitude(newLocation.altitude);    MyGPSCompass.Update;  end;end;{$ENDIF}{$IFDEF FPC}procedure MyCLController.locationManager_dIDUpdateheading(manager: CLLocationManager; newheading: CLheading);begin  if Assigned(MyGPSCompass) then begin    MyGPSCompass.FCompassheading:= newheading.magneticheading;    MyGPSCompass.Update;  end;end;{$ENDIF}constructor TiOSGPSCompass.Create(AOwner: TComponent);begin  inherited;  {$IFDEF FPC}    Controller := MyCLController.alloc.init;  Controller.locationManager := CLLocationManager.alloc.init;    Controller.locationManager.setDelegate(Controller);  Controller.locationManager.setDesiredAccuracy(kCLLocationAccuracyBestForNavigation);    Controller.locationManager.startUpdatingLocation;  Controller.locationManager.startUpdatingheading;  {$ENDIF}  MyGPSCompass:= Self;end;destructor TiOSGPSCompass.Destroy;begin  {$IFDEF FPC}  Controller.locationManager.release;  Controller.release;  {$ENDIF}  inherited;end;procedure TiOSGPSCompass.SetLatitude(value: Double);begin  if (FLatitude <> value) then begin    FLatitude:= value;    UpdateNeeded:= True;  end;end;procedure TiOSGPSCompass.SetLongitude(value: Double);begin  if (FLongitude <> value) then begin    FLongitude:= value;    UpdateNeeded:= True;  end;end;procedure TiOSGPSCompass.SetAltitude(value: Double);begin  if (FAltitude <> value) then begin    FAltitude:= value;    UpdateNeeded:= True;  end;end;procedure TiOSGPSCompass.Setheading(value: Double);begin  if (Fheading <> value) then begin    Fheading:= value;    UpdateNeeded:= True;  end;end;procedure TiOSGPSCompass.Update;begin  if (UpdateNeeded and Assigned(OnUpdate)) then OnUpdate(Self);  UpdateNeeded:= False;end;procedure Register;begin  RegisterComponents('iOS',[TiOSGPSCompass]);end;end.
总结

以上是内存溢出为你收集整理的如何在iOS中访问指南针?全部内容,希望文章能够帮你解决如何在iOS中访问指南针?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1104976.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存