FMX.Map Sample

From RAD Studio Code Examples
Jump to: navigation, search

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

Location

You can find the Map sample project at:

  • Start | Programs | Embarcadero RAD Studio Athens | Samples and navigate to:
    • Object Pascal\Multi-Device Samples\Device Sensors and Services\Map Type Selector
    • CPP\Multi-Device Samples\Device Sensors and Services\Map Type Selector
  • 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 to different map types: Normal, Satellite and Hybrid.
  • Centring the map using a given coordinate.
  • Rotating the map.
  • Working with map markers.

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: Map_ObjectPascal.dproj.
    • C++: map_cpp.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.
Map Sample.png
To interact with the map:
  • Use the Normal, Satellite and Hybrid TSpeedButtons to change among the different map types.
  • Write latitude and longitude map coordinates, and click the Go button to move the center of the map to the indicated coordinates.
  • Rotate the map up to 180 degrees using the TTrackBar.
  • Click on a point in the map to add a map marker.
  • Long-click on a marker to drag that marker.

Files

File in Delphi File in C++ Contains

Map_ObjectPascal.dproj

map_cpp.cbproj

The project itself.

Maps.fmx

Unit1.fmx

The main form where the components are located.

Maps.pas

Unit1.h, map_cpp.cpp

Implementation of the sample.

Implementation

Uses

See Also