Below is a code snippet that shows how to write the delegates that get GPS and Compass heading information from the device.
Don't worry - cleaned up complete examples are forthcoming shortly.
{$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
// Do stuff with newLocation.coordinate.latitude and .longitude here
end;
{$ENDIF}
{$IFDEF FPC}
procedure MyCLController.locationManager_didUpdateHeading(manager: CLLocationManager; newHeading: CLHeading);
begin
// Do stuff with newHeading.magneticheading here
end;
{$ENDIF}
procedure TForm1.FormCreate(Sender: TObject);
begin
{$IFDEF FPC}
Controller := MyCLController.alloc.init;
Controller.locationManager := CLLocationManager.alloc.init;
Controller.locationManager.setDelegate(Controller);
Controller.locationManager.startUpdatingLocation;
Controller.locationManager.startUpdatingHeading;
{$ENDIF}
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{$IFDEF FPC}
Controller.locationManager.release;
Controller.release;
{$ENDIF}
end;
Anders,
ReplyDeleteOutstanding job with all of these iOS examples. I expect that they will be very helpful. Thanks.
Hi,
ReplyDeleteAre you sure this doesn't require you to parse the additional header files for the CoreLocation framework ? I have been trying to use the CLLocationManager from within Delphi, but never succeeded. It should be possible by parsing the additional header files for the required frameworks, but alas ... I never succeeded in doing that ...
Regards,
Stefaan
It does, in fact, require that you parse the CoreLocation headers. I will provide an example of this soon.
ReplyDeleteI find your iOS FireMonkey blog entries very interesting, and educational. Keep them coming.
ReplyDeleteOne issue though - are you able to fix the formatting of the code (add syntax highlighting)? In the current state, it is quie difficult to read.
Well ... once I know how to parse / build the other iOS FrameWorks, I will surrely make another Delphi XE2 / FireMonkey tutorial on that topic.
ReplyDeleteAnders,
ReplyDeleteThank you so much for sharing these nice tips and tricks. I can't wait getting started with Firemonkey.
You should probably fix the orientation of the compass-dial - it is pointing towards 29 degrees - not 331 ;o)
best regards
Jan
ehh - unless the dot is north.....
ReplyDeleteSorry....
最新
ReplyDeleteI was able to find good information from your blog posts.
ReplyDeleteMy pal advisable I may such as this internet site. He or she once was entirely proper.. Day4deal Every Day The Best Deals This organize truly made our day. You actually can not consider simply just how a whole lot time frame I needed used just for this information and facts! Thank you!
ReplyDeleteIs there a service available that geotags blog posts while on the go and is able to post to map with others?
ReplyDeleteSupercharge your marketing campaign with our social media promotion services. Buy high quality likes/followers/views at highly competitive prices and with fast delivery.
ReplyDeleteGet 5,000 Twitter Followers from:- http://khalaghor.com/twitter.html
You can also order smaller or bigger package from our official website.