Firemonkey'de iphone pusulasına nasıl erişirim?iOS'ta pusulaya nasıl erişebilirim?
cevap
İşte howto video yer almaktadır: http://blogs.embarcadero.com/ao/2011/10/13/39171
Tam kaynak kodu: http://cc.embarcadero.com/item/28536
Ve (kısa) madde: http://edn.embarcadero.com/article/41715
Ve burada bir pusula bileşeni için kaynak kodu var.
Henüz denemediniz, ama işe yaramalı.
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 İyi olsa da, eğer cevabınıza dahil olan ilgili parçaların hepsinin olması mümkün olsa iyi olur. – jpfollenius
@Smasher, Ne yapabileceğimi göreceğim. – Johan
@Smasher, bir pusula bileşeni – Johan
- 1. package.json config bölümüne nasıl erişebilirim?
- 2. UPnP cihazının servislerine nasıl erişebilirim?
- 3. DizinlenmişDB'ye nasıl senkronize olarak erişebilirim?
- 4. UISegmentedControl'e UICollectionViewController başlığına nasıl erişebilirim?
- 5. asp.net'de içsel bilgilere nasıl erişebilirim
- 6. Hatırlatıcılara nasıl programatik olarak erişebilirim?
- 7. Bir webmethod'ta oturuma nasıl erişebilirim?
- 8. JSP'deki javascript değişkenlerine nasıl erişebilirim?
- 9. Cihazda logcat dosyasına nasıl erişebilirim
- 10. Android'de tüm çekilişlere nasıl erişebilirim?
- 11. allowScriptAccess'in değerine Flash'tan nasıl erişebilirim?
- 12. Tarayıcıdan donanım zamanına nasıl erişebilirim
- 13. FreeMarker şablonumdaki kök çekirdeğe nasıl erişebilirim?
- 14. İç içe hücre dizilerine MATLAB'de nasıl erişebilirim?
- 15. Reaktiflerdeki bir geçiş durumuna nasıl erişebilirim?
- 16. VBA'da kayıtsız bir COM bileşenine nasıl erişebilirim?
- 17. Proje haritasına bir leiningen eklentisinden nasıl erişebilirim?
- 18. Scala play'den post verilere nasıl erişebilirim?
- 19. Team Foundation Server Workspace'e nasıl erişebilirim?
- 20. Koddaki C# performans sayacına nasıl erişebilirim?
- 21. İzleme tablomda C# 'ya nasıl erişebilirim?
- 22. $ _SERVER içinde görünmeyen istek başlıklarına nasıl erişebilirim?
- 23. Ebeveyn denetleyicisinde $ formatters.push işlevinin geçerliliğine nasıl erişebilirim
- 24. Yüce metin 3 python kabuğuna nasıl erişebilirim?
- 25. backbone.js: Yuvalanmış koleksiyonun üst modeline nasıl erişebilirim?
- 26. Chrome'un yazım denetimi sözlüğüne nasıl erişebilirim?
- 27. Paylaşılan bir sözlüğe çoklu işlemeyle nasıl erişebilirim?
- 28. Amazon DynamoDB'ye Python üzerinden nasıl erişebilirim?
- 29. Facelets sayfasındaki oturum özniteliğine nasıl erişebilirim?
- 30. Preg_replace_callback içindeki bir değişkene nasıl erişebilirim?
Anlayamıyorum, bu bir şey gibi: Soruyorum, cevabı veriyorum? – RBA
@RBA, yalnızca yer işaretimi paylaşıyorum. Umarım yararlıdır. SO bunun için izin verir, SSS bakın. – Johan
Gerçekten de siz gerçekten haklısınız, bu size bir +1 vermenin sebebiydi. IMHO, bu da wiki üzerine konulmalı çünkü iOS geliştirmede iyi bir soru var – RBA