Composant Delphi / Google Maps / OpenStreetMap / Leaflet  / Mappilary / Native Maps 100% Delphi 0% WebBrowser 0% Javascript

Location

you are here :TECMap

API Keys

TECNativeMap uses MapQuest with a key for the free plan limited to 15000 transactions per month.

If you want to use these services you must obtain a key from MapQuest.

Do the same to use the services of MapZen and MapBox.

Offline mode

If you specify a directory in the LocalCache property, all your geolocation data will be cached and can be reused in offline mode.

Address format

You benefit from the services of geolocation via the property GeoLocalise de type TECGelocalise

The Address property gives you the address of the center of the map, it is of type string and is accessible in read/write

TECGeolocalise uses the services of OpenStreetMap and OpenMapQuest

You can also use ArcGis through functions
function TECGeolocalise.ArcGisReverse(const Lat,Lng:double):string;
function TECGeolocalise.ArcGisFind(const data:string;var Lat,Lng:double):boolean;

Geolocalisation

To obtain the address of a specific you have the function GetAddressFromLatLng(const dLatitude,dLongitude:double):string;

You can get the various parts of the address by using the property TECGeolocalise.ReverseResults:TStringList

adr := map.GetAddressFromLatLng(Latitude,Longitude) ;

// now ReverseResults contains tags in nominatim <addressparts>

country := map.Geolocalise.ReverseResults['country'];
road := map.Geolocalise.ReverseResults['road'];
postcode:= map.Geolocalise.ReverseResults['postcode'];
...

You can get the coordinates of an address with the function GetLatLngFromAddress(const sAddress:string;var dLatitude,dLongitude:double):boolean;

By assigning a value to the property Address you will change the position of the center of your map to match to the address

Places

TECGeolocalise allows you to search specific locations in a data area, for example to find restaurants within a radius of 500 metres.

It is Overpass-api that uses data from OpenStreetMap which is used

The property TECGeolocalise.Places.XapiServer allows you to use another server Xapi than MapQuest

// Delphi map component ECMap
// use overpass-api.de

map.GeoLocalise.Places.XapiServer := 'http://www.overpass-api.de/api/xapi?';
procedure Search( Tags:string);

Launch a search, tags contains the query

Documentation Xapi

// Delphi map component ECMap
Map.geolocalise.OnSearch := mapPlacesSearch;

Map.GeoLocalise.Places.latitude := map.latitude;
Map.GeoLocalise.Places.longitude := map.longitude;

Tags := 'node[amenity=restaurant]';


// 500 meters
Map.GEoLocalise.Places.radius := 500;

Map.GEoLocalise.Places.Search(Tags);

...

procedure TForm.mapPlacesSearch(sender: TObject);
var
i, max: Integer;
types, names: string;
begin

if map.GEoLocalise.Places.Status <> 'OK' then
exit;

max := map.GEoLocalise.Places.results.count - 1;

for i := 0 to max do
begin

types := map.GEoLocalise.Places.results[i].result['types'];
names := map.GEoLocalise.Places.results[i].result['name'];
end;

end;


When the search is complete, the Geolocalise.OnSearch event is raised

Each launch of Search clears the results of a previous search

26
property Adress : string read FAdress write FAdress;
Property read/write indicating the focal point of the search box, it takes precedence over the properties Latitude et Longitude
property Status : string;

Property read-only that returns a string indicating the status of the search, 'OK' if all went well

The status is available in the event GeoLocalise.OnSearch

property ItemDetail : integer;
Property read-only that contains the index of the result which is more details
property Latitude : double;
Property read/write that indicates the latitude of the central point of the area of research, this invalid the contents of the property Address
property Longitude: double;
Property read/write indicating the longitude of the central point of the area of research, this invalid the contents of the property Address
property Radius : integer;
Property read/write that indicates the radius of search in metres
property maxResult : integer;
limits the number of results for a search in the OpenStreetMap data
property Searching: boolean;
Propriété en lecture seule qui indique si une recherche est en cours
property Results:TECPlaceResults;
Results list, the OnPlacesSearch event is raised when the results are available

TECPlacesResults

This class manages the list of the results returned by Search

procedure Clear;
Clears all the results
function Count:integer;
Returns the number of result for the query
procedure Delete(const index:integer);
Clears the result which we pass the index
property Result[index:integer]:TECPlaceResult
Table allowing access to results

TECPlaceResult

Class handling a result corresponding to a search

property Result[const key:string]:string;
Returns the value of the key that is passes as a parameter
property Detail[const Key:string]:string;
Returns the value of the key that is passes as a parameter for details
property NameResult[const index:integer]:string;
Returns the key of a result based on its index
property NameDetail[const index:integer]:string;
Returns the key of a detail based on its index
property CountResult:integer;
Returns the number of result element (key = value)
property CountDetail:integer read getCountDetail;
Returns the number of a detail element (key = value)
property Latitude : double;
Latitude of the result
property Longitude: double;
Longitude of the result
property RawResult : string;
Returns the set of the result elements in the form of a string of rows key = value
property RawDetail : string;
Returns the set of elements of the detail in the form of a string of rows key = value

DemonativeLocalise

the DemoNativeLocalise program shows you how to manage Places

Fig. 81 DemoLocalise
Fig. 81 DemoLocalise

Geofences

Geofence is a virtual area that triggers an alert when you enter or exit.

function Add(const Lat,Lng:double;const RadiusMeter:integer;const Name:string=''):integer;overload;

Adds a circular area defined by its center point and RADIUS in meters.

map.geofences.add(43.231572,0.080853,50);
function Add(const dLatLngs: array of double;const Name:string=''):integer;overload;

Adds a polygonal area defined by an array containing the various points

map.geofences.add([lat1,lng1,lat2,lng2,lat3,lng3],"triangle");
function Add(const Polygone:TECShapePolygone;const Name:string=''):integer;overload;

Adds a polygonal area defined by a polygon

map.geofences.add(map.shapes.polygones[0]);
procedure Delete(index:integer);
Delete a geofence
function Count:integer;
Returns the number of geofences
function IndexOf(value:TECBaseGeofence):integer;
Returns the index of the geofence
procedure Clear;
Clears all the geofences
property Active : boolean ;
Activate or not the geofences detection
property toTxt:string ;

Import / export geofences in text format

By default, when you Save the map in text format the geofences are saved and can be recharged

property Geofence[index : integer]:TECBaseGeofence ;
Returns a geofence

TECBaseGeofence

property TECBaseGeofence.Name:string ;
Name of the geofence
property TECBaseGeofence.Active : boolean
Activate or not the geofence (enabled by default)
property TECBaseGeofence.ActiveDuration : integer

Maximum activation time (milliseconds) (default 0 infinite)

// Activate for 3 seconds
map.geofences.geofence[0].ActiveDuration := 3000;
property Color : TColor ;
Color of the area
property HoverColor : TColor ;
Color of the area when mouseover
property Item : TObject;
You can use this property to store your data
property Tag : integer;
You can use this property to store your data
property TECBaseGeofence.Shapes : TECShapesList
The list of items that are currently in the geofence

Évenements Geofences

To respond connect you on OnEnterGeofence and OnLeaveGeofence of TECNativeMap events.

...
map.OnEnterGeofence := mapEnterGeofence;
map.OnLeaveGeofence := mapLeaveGeofence;
...
procedure TForm1.mapEnterGeofence(sender: TObject; const Geofence: TECBaseGeofence; const item: TECShape);
begin
caption := 'item '+inttostr(item.id)+' enter in '+Geofence.Name;
end;

procedure TForm1.mapLeaveGeofence(sender: TObject; const Geofence: TECBaseGeofence; const item: TECShape);
begin
caption := 'item '+inttostr(item.id)+' leave '+Geofence.Name;
end;

The detection is done when a shape is moved, the test is performed on location (latitude and longitude) not on the actual surface of the object.

Fig. 82 Demo Geofences

go to page
© 2016 ESCOT-SEP Christophe - Made width Help&Web - RSS - Google+