This visualization sample demonstrates the use of the TMapView class. We will show 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.
Table of Contents
You can find the Tabbed Map sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and navigate to:
Object PascalMulti-Device SamplesDevice Sensors and ServicesMaps
CPPMulti-Device SamplesDevice Sensors and ServicesMaps
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the sample repositories according to your RAD Studio version.
Visualization with 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 Do We Use the Sample?
- Navigate to one of the locations given above and open:
- Delphi: TabbedMapProject.dproj.
- C++: TabMapProject.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.
- 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.
|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.|
Maps Visualization 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 is 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.
If you want to check the original post, follow the link below:
Interested in developing Android and Windows applications with a map visualization on Delphi or c++ environments? Try the Windows UI Toolkit.