FMX.Tabbed Map Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample shows how to use maps in different tabs in a Delphi/C++ application.

Location

You can find the Tabbed Map sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and navigate to:
    • Object Pascal\Multi-Device Samples\Device Sensors and Services\Maps
    • CPP\Multi-Device Samples\Device Sensors and Services\Maps
  • 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 sample demonstrates the use of the TMapView class. The sample shows how to display and interact with the map, including:

  • Changing between two tabs that display different maps.
  • Showing the coordinates of the map center.
  • Zooming in and zooming out both maps.

Using Google Maps on Android

If you are running this sample on Android, in order to access the Google Maps servers, you have to add a Maps API key to the sample. To acquire the API key and add it in the sample you need to follow these configuration steps:

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: TabbedMapProject.dproj.
    • C++: TabMapProject.cbproj.
  2. If you are running the sample on Android, ensure you first follow the steps indicated in Using Google Maps on Android
  3. Before you run the sample, ensure the device is connected to the Internet.
  4. Press F9 or choose Run > Run.
  5. When you run the sample, the TMapView loads the map.
Tabbed Map Sample.png
To interact with the map:
  • Use the Saint-Pétersbourg and San Francisco tabs to change between the two maps.
  • Change the zoom using the Zoom out and Zoom in buttons.
  • Move the map and see the coordinates of the map center in the CameraInfo TLabel, at the button of the app.

Files

File in Delphi File in C++ Contains

TabbedMapProject.dproj

TabMapProject.cbproj

The project itself.

TabbedMap.fmx

TabbedMap.fmx

The main form where the components are located.

TabbedMap.pas

TabbedMap.h, TabbedMap.cpp

Implementation of the sample.

Implementation

  • The sample uses TMapView to display and manage the maps.
  • TMapCoordinate is used to create the initial coordinates with the indicated latitude and longitude. Then, the center of the maps are set to such coordinates with the TMapView.Location property.
  • The TMapView.Zoom property is used to set the initial zoom of both maps to 10. This same property, is also used to zoom in and zoom out both maps by adding or subtracting 1 to the Zoom property.
  • TMapView.OnCameraChanged updates the CameraInfo TLabel that indicates the Latitude and Longitude of the map Location.

Uses

See Also