The new maps component in RAD Studio XE8 makes it easy to add mapping functionality to your mobile applications. TMapView provides access to map APIs for iOS and Android. On Android, it uses the Google Maps Android API and on iOS, it uses the Map Kit Framework.
The key features of the TMapView component are:
- Four Types of Maps: Normal, Satellite, Hybrid and Terrain (Android only)
- Gesture Control: Intuitive tilt, rotate and zoom gesture controls
- Control the Map View: Ability to control the map properties such as the map center coordinates, the map orientation and so on
- Custom markers: Ability to add markers to the maps
If you are using TMapView on Android, you will need to obtain a Google Maps API key.
RAD Studio XE8 ships with two maps sample applications for Object Pascal and C++.
Object Pascal:
- C:\Users\Public\Documents\Embarcadero\Studio\16.0\Samples\Object Pascal\Mobile Samples\Device Sensors and Services\Maps
- C:\Users\Public\Documents\Embarcadero\Studio\16.0\Samples\Object Pascal\Mobile Samples\Device Sensors and Services\Map Type Selector
C++:
- C:\Users\Public\Documents\Embarcadero\Studio\16.0\Samples\CPP\Mobile Samples\Device Sensors and Services\Maps
- C:\Users\Public\Documents\Embarcadero\Studio\16.0\Samples\CPP\Mobile Samples\Device Sensors and Services\Map Type Selector
I created a small demo project that uses the Spitcast REST API, REST component framework, FDMemTable and TMapView to display surf locations on my map based on the longitude, latitude and spot name information returned from the REST service. A custom marker graphic in the shape of a surfboard fin is used to indicate the locations on the map.
You can download my demo project here.
Here is a code snippet from the demo project:
procedure TForm26.FormCreate(Sender: TObject); var LongitudeField: TField; LatitudeField: TField; MyLocation: TMapCoordinate; Descr: TMapMarkerDescriptor; SpotName : TField; begin RESTRequest1.Execute; begin LongitudeField := FDMemtable1.FieldByName('longitude'); LatitudeField := FDMemtable1.FieldByName('latitude'); SpotName := FDMemTable1.FieldByName('spot_name'); FDMemTable1.First; while not FDMemTable1.EOF do begin MyLocation := TMapCoordinate.Create(StrToFloat(LatitudeField.AsWideString),StrToFloat(LongitudeField.AsWideString)); MapView1.Location := MyLocation; Descr := TMapMarkerDescriptor.Create(MyLocation, SpotName.AsWideString); Descr.Icon := BitmapSource.Bitmap; BitmapSource.Visible := True; Descr.Draggable := True; MapView1.AddMarker(Descr); MapView1.Zoom := 8; FDMemTable1.Next; end; end; end;
Here is the app running on my iPad: