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

Places

you are here :TECMap

Property Places type TECPlaces lets you search specific locations in a given area, such as finding restaurants in a radius of 500 meters.

With the Google API you'll use the service Places with other you use xapi MapQuest API Service that uses data of OpenStreetMap, this causes a small difference in the syntax of the research we detail thereafter.

You can force the use of Xapi under Google by setting the property UseOpenMapQuestServices

2

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

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

map.XapiServer := 'http://www.overpass-api.de/api/xapi?';

Google Places is limited to 20 results per query

3

TECPlaces

procedure Search( Tags:string);

Launch a search, tag contains the query, the syntax varies depending on the Google API or CloudMade

List of tags available in Google Documentation for xapi CloudMade// Delphi map component ECMap
var Tags:string;
begin
map.Places.Latitude := map.latitude;
map.Places.Longitude:= map.Longitude;
// syntaxe change with api
case map.MapAPI of
apigoogle : begin
if ckStore.checked then
Tags := 'store'
else
if ckRestaurant.checked then
Tags := 'restaurant'
else
if ckDoctor.checked then
Tags := 'doctor';
end;

else begin

if ckStore.checked then
Tags := 'node[shop=*]'
else
if ckRestaurant.checked then
Tags := 'node[amenity=restaurant]'
else
if ckDoctor.checked then
Tags := 'node[amenity=doctors]';
end;
end;

// 500 meters
map.Places.Radius := 500;
// run search
map.Places.Search(Tags);

When the search is completed, the event OnPlacesSearch is triggered

Each launch of Search erases the results of a previous search

4
propcedure TextSearch(const TextQuery: string);

Launch of a textual search, only available with the api language Google search

When the search is complete, the event OnPlacesSearch is raised

property AutoComplete : boolean

Displays a field of research auto complete, only available with api Google

When a selection is complete, the OnPlaceAutoComplete event is raised

Fig. 33 Place AutoComplete

If you want to adjust the size of the search box to the width of the card, connect you on the OnResize event and add this line

map.Javascript('input_autocomplete.style.width="'+inttostr(map.Width-160)+'px"');
property Adress : string read FAdress write FAdress;
Property read / write indicates that the focus of the search area, it takes precedence over the properties Latitude and Longitude
property Status : string;

Read-only property that returns a string indicating the status of research, 'OK' if all went well

The status is available in the event OnPlacesSearch

property ItemDetail : integer;
Read-only property that contains the index of the result which we seek further details
property Latitude : double;
Property read / write that indicates the latitude of the midpoint of the search area, this invalidates the contents of the Property Address
property Longitude: double;
Property read / write that indicates the longitude of the midpoint of the search area, this invalidates the contents of the Property Address
property Radius : integer;
Property read / write indicating the search radius in meters
property useOSM : boolean;
Use data from OpenStreetMap with the api Google
property maxResult : integer;
limits the number of results for a search in OpenStreetMap, ignored with Google Places
property Searching: boolean;
Read-only property that indicates whether a search is underway
property Results:TECPlaceResults;
List of results, the event OnPlacesSearch is triggered when results are available

TECPlacesResults

This class manages the list of results returned by Search

procedure Clear;
Erases all results
function Count:integer;
Returns the number of results matching the query
procedure Delete(const index:integer);
Clears the results of which we pass the index
property Result[index:integer]:TECPlaceResult
Table that allows access to the results, it is the default property so you can access it directly by map.Places.Results [index] instead of map.Places.Results.Result [index]

TECPlaceResult

Managing a class match for a search

procedure getDetails;

Performs a query on the result for further details

Not available CloudMade

3

When details are available the event OnPlacesDetail is triggered .

property Result[const key:string]:string;
Returns the key value which is passed as parameter
property Detail[const Key:string]:string;
Returns the key value which is passed as a parameter for details
property NameResult[const index:integer]:string;
Returns the key of a result in terms of its index
property NameDetail[const index:integer]:string;
Returns the key of a detail according to its index
property CountResult:integer;
Returns the number of elements (key = value) of a result
property CountDetail:integer read getCountDetail;
Returns the number of elements (key = value) of a detail
property Latitude : double;
Latitude result
property Longitude: double;
Longitude result
property RawResult : string;
Returns all the elements of the result as a string consisting of key = value lines
property RawDetail : string;
Returns all the elements of detail as a string consisting of key = value lines

// Delphi map component ECMap

// Event OnPlacesSearch
procedure TFDemoLocalise.mapPlacesSearch(Sender: TObject);
var i:integer;
iMarker : integer;
s,icon,types,names: string;
begin

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

for i:=0 to map.Places.Results.count-1 do
begin


types:= map.Places.Results[i].result['types'];
names:= map.Places.Results[i].result['name'];

// add a marker for all valid résult
if (names<>'') then
begin

iMarker := map.AddMarker(map.Places.Results[i].latitude,map.Places.Results[i].longitude);

if iMarker>-1 then
begin
// select icon for types
if pos('restaurant',types)>0 then
icon := 'http://google-maps-icons.googlecode.com/files/restaurant.png'
else
if pos('doctor',types)>0 then
icon := 'http://google-maps-icons.googlecode.com/files/doctor.png'
else
icon := 'http://google-maps-icons.googlecode.com/files/supermarket.png';

map.Markers[iMarker].icon := icon;
map.Markers[iMarker].tag := FStartPlace+i;
map.Markers[iMarker].infoWindow := map.InfoWindows.Add(names);
map.InfoWindows[map.Markers[iMarker].infoWindow].Anchor := iMarker;

end;

end;

end;


end;

Demonstration

the program DemoLocalise shows you how to manage Places
Fig. 34 DemoLocalise
Fig. 34 DemoLocalise
go to page
© 2016 ESCOT-SEP Christophe - Made width Help&Web - RSS - Google+