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
2The XapiServer property allows you to use another server Xapi than MapQuest
// use overpass-api.de
map.XapiServer := 'http://www.overpass-api.de/api/xapi?';
Google Places is limited to 20 results per query
3TECPlaces
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
4Launch of a textual search, only available with the api language Google search
When the search is complete, the event OnPlacesSearch is raised
Displays a field of research auto complete, only available with api Google
When a selection is complete, the OnPlaceAutoComplete event is raised
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
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
TECPlacesResults
This class manages the list of results returned by Search
TECPlaceResult
Managing a class match for a search
Performs a query on the result for further details
Not available CloudMade
3When details are available the event OnPlacesDetail is triggered .
// 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;