FMX.Location Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use the TLocationSensor component in order to read the GPS location of the device and display it on the form. The sample also shows you how to display Google Maps in a web browser in order to accurately pinpoint the location of the device on a map.

Location

You can find the Location sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and then navigate to:
    • Object Pascal\Mobile Snippets\Location
    • CPP\Mobile Snippets\Location
  • Subversion Repository:
    • You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

The Location sample demonstrates how to use the location sensor of the device on iOS applications. The sample uses TLocationSensor to offer information about the GPS location of the device. Moreover, the sample displays the location of the device on Google Maps using TWebBrowser.

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: Location.dproj.
    • C++: Location.cbproj.
  2. Select the iOS platform.
  3. Press F9 or choose Run > Run.
  4. Interact with the sample:
    • Enable the Location Sensor to get the Latitude and Longitude values of the location of your device.
    • See the location of your device displayed on Google Maps.
    • Move the device in order to see how the location sensor can monitor the location changes of the device.
    • Change the Trigger Distance and Accurancy properties and interact with the sample another time.

Files

File in Delphi File in C++ Contains

Location.dproj

Location.cbproj

The project itself.

uMain.fmx

uMain.fmx

The main form where the components are located.

uMain.pas

LocationPCH.h, Location.cpp

Used to define and implement the sample.

Information.txt

Information.txt

Further information about the sample.

Classes

TLocationForm is the main form that represents the main window of the sample. It contains the following components:

Implementation

  • The sample uses TLocationSensor to determine the location information of your device.
  • The sample uses TWebBrowser to load and display content from a URL address (Google Maps in this sample).
  • The sample uses TSwitch to provide the user with a two-way on-off switch. TSwitch on enables TLocationSensor.
  • The sample uses TListBox to display a set of items of TLocationSensor information in a scrollable list.

When you run the application, TLocationSensor is disabled. You can enable the location sensor by switching the swlocationSensorActive. If TLocationSensor is enabled, it reads the GPS location of the device and displays it on Google Maps using a web browser in order to accurately pinpoint the location of the device on a map. Then, the sample uses the LocationChange, Accuracy and Distance properties of TLocationSensor to monitor location changes and trigger OnLocationChanged whenever there is a location change.

Uses

See Also

Samples