tComposant Delphi / Google Maps / CloudMade / OpenMapQuest / Leaflet  / Bing Maps
Google Maps
Google Earth
CloudMade
OpenMapQuest
LeafLet

Location

Property Address gives the address of the card, it is of type string and is read / write

Address format

To find an address you can use a free format such as "address, city, ZIP".

CloudMade and OpenMapQuest use Nominatim Search Service

Limitation of geolocation

Converting coordinates / address opens a connection to the server of your card provider, Google is setting up a quota system to avoid too much demand in the shortest time.

If you exceed this limit event OnJavascriptError (sender: Tobject;const sError:string) is raised with sError = 'OVER_QUERY_LIMIT'

ECMap implements a caching system which means that as the coordinates do not change the connection on the server takes place only for the initial consultation, so you can perform multiple read and not worry about the quota.

The system cache is valid for all objects for their geolocation, such as Markers

12

Geolocation

To get the address of a specific point you have the function GetAdressFromLatLng(const dLatitude,dLongitude:double):string;

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

By assigning a value to the property address, you'll change the position of the center of your card to match it to the address

// Delphi map component ECMap
// move center of map
map.Adress := 'Tarbes';


This will trigger the event OnAdress (sender: Tobject;const sAdresses:string;var Index:integer)

GetLatLngFromAdress also triggers OnAdress

1

sAdresses contain all addresses, separated by #13#10 may correspond with your request.

Index contain the index of the selected address, default 0, you can change it in this event.

Output from this event the center of the map corresponds with the address selected

Property Adresses type TGeoCoderReponses contains all the answers returned by the server.

Example of use

// Delphi map component ECMap
// move center of map with response 2
if map.Adresses.count>1 then
map.setCenter(map.Adresses[1].Latitude,map.Adresses[1].Longitude);


Geolocation asynchronous

GetAdressFromLatLng, GetLatLngFromAdress et Adress := 'paris' await the results of the query, you have at your disposal two procedure asynchronous (nonblocking) equivalent.

procedure GeoLocationFromLatLng(const dLatitude,dLongitude:double);

under CloudMade this procedure is blocking but not GeoLocation

2

procedure GeoLocation(const sAdress:string);

Both procedures trigger event OnGeolocation (sender:Tobject;const dLatitude,dLongitude:double;const sAdresse:string);

dLatitude,dLongitude et sAdresse correspond to the first response available like for functions synchronous Adresses contains all the results.

You can use the component TComboBox to contain both the query and the result thereof, the demo shows you how DemoLocalise

1

Fig. 26 Using a TComboBox to manage the geolocation

PropertiesTGeoCoderReponses

property Adresses:string
The list of addresses separated by any #13#10

property Adresse[index:integer] : string
The address number Index

property Error [index:integer] : string
The possible error

property Latitude[index:integer] : double
Latitude corresponding to the address Index

property Longitude[index:integer] : double
Longitude corresponding to the address Index

property LocationType[index:integer]: string
The accuracy of the answer (only for google)

History answers

Each geolocation will change the contents of the property Adresses, you can store it in a list spécilisée, accessible from the property ListAdresses type TListGeoCoderReponses, for future use, is the right time in the event OnAdress

PropertiesTListGeoCoderReponses

function Add(const geoCode:TGeoCoderReponses):integer;

Adds value in the list TGeoCoderReponses

function count:integer;

Number of stored TGeoCoderReponses

procedure clear;

Clears all values

procedure Delete(const index:integer);

Removes the index value index

property GeoCoderReponses[index:integer]:TGeoCoderReponses;

Read / write access to values by their index

Using ListAdresses

The typical usage of this list is where you must manage a starting address and arrival, demos and DEMOmobile DemoRoutes shows you a way to.

A ComboBox is used for departure and arrival, during validation of an address by RETURN Geolocation is request.

In the event OnAdress is stored in the ComboBox addresses in clear, placed in ListAdresses full data returned by the query, and stores the index into the tag property of the combobox.

We can then obtain the coordinates of any address placed in the ComboBox.


// Delphi map component ECMap

// sample for DemoMobile

{*
press RETURN key on combobox start and destination for Geolocalize adress

fired event OnAdress
}
procedure TFDemoMobile.cbStartKeyPress(Sender: TObject; var Key: Char);
var lat,lng : double;
begin
if Key=#13 then
begin
FComboQueryAdress := Sender As TComboBox;
if assigned(FComboQueryAdress) then
map.GetLatLngFromAdress(FComboQueryAdress.text,lat,lng)
end;
end;


{*
event OnAdress

fired by map.GetLatLngFromAdress(...)

@param sender instance of component TECMap
@param sAdresses list of possible addresses (adr0#13#10adr1#13#10...)
@param index selected index adress

}
procedure TFDemoMobile.mapAdress(sender: TObject; const sAdresses: String;
var Index: Integer);
begin
if assigned(FComboQueryAdress) then
begin
FComboQueryAdress.Items.text := sAdresses;
FComboQueryAdress.ItemIndex := index;

// save actuel map.Adresses in map.ListAdresses
// Add value if necessary
if FComboQueryAdress.Tag>-1 then
map.ListAdresses[FComboQueryAdress.Tag] := map.Adresses
else
FComboQueryAdress.Tag := map.ListAdresses.Add(map.Adresses);

end;
end;

// Find Latitude, Longitude of ComboBox Itemindex
function TFDemoMobile.SelectLatLng(const cb : TComboBox;var Lat,Lng:double):boolean;
begin

result := false;

if not assigned(cb) then exit;

if cb.ItemIndex>-1 then
begin
if (cb.Tag>-1)and(cb.Tag<map.ListAdresses.count) then
begin
Lat := map.ListAdresses[cb.Tag].latitude[cb.ItemIndex];
Lng := map.ListAdresses[cb.Tag].longitude[cb.ItemIndex];

result := true;
end;

end;

end;


Use the Open Map Quest services with Google maps

By switching the property UseOpenMapQuestServices to true you use OpenMapQuest for all that concerns the geolocation, the altitude and places

go to page
© 2012 ESCOT-SEP Christophe - Made width Help&Web - RSS
Site Meter