Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:39:41+00:00 2026-05-26T15:39:41+00:00

How do I access the iphone compass in Firemonkey?

  • 0

How do I access the iphone compass in Firemonkey?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:39:42+00:00Added an answer on May 26, 2026 at 3:39 pm

    Here’s a howto video: http://blogs.embarcadero.com/ao/2011/10/13/39171
    Full source code: http://cc.embarcadero.com/item/28536
    And a (short) article: http://edn.embarcadero.com/article/41715

    And here’s source code for a compass component.
    Have not tried it yet, but it should work.

    unit Compass;
    
    {Based on Anders Ohlsson Firemonkey Compass example}
    
    {$IFDEF FPC}
    {$mode objfpc}{$H+}
    {$modeswitch objectivec1}
    {$ENDIF}
    
    interface
    
    uses
      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.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Know if it's possible to access the iPhone compass in Safari using JavaScript? I
Is there any way to access the iPhone/iPod touch settings programatically ? Thanks. Biranchi
Is there any difference(means full/limited access) in iphone SDK before and after enrolling in
How to change iPhone APN (Access Point Name) programmatically? Or force a 3G/GPRS connection
Are there any way to access or set iphone's alarm? Im assuming if this
The iPhone SDK docs claim fopen() is a supported method of file access but
Can I access the text of my SMS messages using the iPhone SDK? Meaning
I'm writing a simple iPhone app which lets a user access a series of
When using one's own iPhone for development it's easy enough to access any crash
I am programming my first iPhone app (which crashes with an EXC BAD ACCESS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.