FMX.Map Sample
This sample shows how to use maps in a Delphi/C++ application.
Contents
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:
- Getting your Google Maps API key:
- Retrieving Your Application Certificate
- Creating an API Project in the Google APIs Console. This step requires you to have a Google Account.
- Requesting the Maps API Key
- Configuring the sample project options. Once you have the Maps API Key; in RAD Studio:
- Go to Project > Options > Version Info
- Select Android platform as Target (either in Debug, Release or All Configurations).
- Add the Maps API Key value in the apiKey key, and click OK.
How to Use the Sample
- Navigate to one of the locations given above and open:
- Delphi: Map_ObjectPascal.dproj.
- C++: map_cpp.cbproj.
- If you are running the sample on Android, ensure you first follow the steps indicated in Using Google Maps on Android
- Before you run the sample, ensure the device is connected to the Internet.
- Press F9 or choose Run > Run.
- When you run the sample, the TMapView loads the map.
- 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
- The sample uses TMapView to display and manage the map.
- The TMapView.Bearing property is used to change the inclination of the map in degrees according to TTrackBar.Value. Since the maximum value of the track bar is 180, the maximum map rotation allowed is 180 degrees.
- The TMapView.MapType property is used to change among the different map types; this sample uses Normal, Satellite and Hybrid.
- The TMapView.OnMapClick event is used to add a map marker on the position clicked by the user.
- The TMapView.Location is used to center the view of the map to a particular map coordinate with the indicated latitude and longitude.
Uses
- FMX.Maps.TMapView
- FMX.Maps.TMapView.Bearing
- FMX.Maps.TMapView.MapType
- FMX.Maps.TMapView.OnMapClick
- FMX.Maps.TMapView.Location
- FMX.Maps.TMapMarkerDescriptor
- FMX.Maps.TMapCoordinate
- FMX.Maps.TMapType