Come accedere alla bussola iphone in Firemonkey?Come accedere alla bussola in iOS?
risposta
Ecco un video howto: http://blogs.embarcadero.com/ao/2011/10/13/39171
Il codice sorgente completo: http://cc.embarcadero.com/item/28536
E un (breve) articolo: http://edn.embarcadero.com/article/41715
Ed ecco il codice sorgente per un componente della bussola.
Non ho ancora provato, ma dovrebbe funzionare.
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.
+1 Sarebbe bello, però, includere le parti rilevanti nella tua risposta se questo è possibile. – jpfollenius
@Smasher, vedrò cosa posso fare. – Johan
@Smasher, aggiunto codice sorgente per un componente bussola – Johan
- 1. accesso alla bussola dell'iPhone con JavaScript
- 2. Come accedere alla vista di UITableViewRowAction iOS 8
- 3. Guida della bussola alla destinazione GPS
- 4. iOS: come accedere a `UIKeyboard`?
- 5. iOS: creazione di una bussola 3D
- 6. come accedere alla cartella download in Android?
- 7. Come accedere alla richiesta in JspTags?
- 8. Come accedere alla mia webcam in Python?
- 9. Come accedere alla stringa presente in string.xml
- 10. Come accedere alla finestra $ in un Provider?
- 11. Come accedere all'accelerometro iOS in Delphi XE2?
- 12. La bussola Android punta alla mia posizione anziché a nord
- 13. Come installare la bussola in mac?
- 14. SBT: come accedere alla variabile di ambiente o alla configurazione?
- 15. Come accedere alla videocamera sui telefoni Android?
- 16. Come accedere alla webcam con Javascript
- 17. Typo3 eID, come accedere alla configurazione
- 18. ASP.NET: come accedere alla sessione dal gestore?
- 19. Come accedere alla matrice in modo circolare in javascript
- 20. Accedere alla base 2 in python
- 21. Simulatore iOS e XCode per simulare la bussola?
- 22. Utilizzare la bussola iOS nativa all'interno di un'app
- 23. Come accedere alla cache dei modelli? - Django
- 24. Come accedere alla mia chiave pubblica SSH?
- 25. Come accedere alla sessione nel file .ashx?
- 26. Come mostrare la bussola sullo schermo?
- 27. Come leggere la bussola Android?
- 28. AFOAuth2Client non è in grado di accedere alla risorsa
- 29. Come accedere alla memoria locale HTML5 creata da PhoneGap su iOS?
- 30. come accedere alla variabile di classe per stringa in Python?
Non capisco, questo è qualcosa di simile: chiedo, do la risposta? – RBA
@RBA, basta condividere il mio segnalibro. Spero sia utile SO lo consente, vedi le FAQ. – Johan
Infatti :) hai perfettamente ragione, questo è stato il motivo per darti un +1. IMHO, questo dovrebbe anche essere messo su wiki perché è una buona domanda sullo sviluppo di iOS – RBA