Что нового
  • Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Free Route Directions with OpenRouteService in TMS FNC Maps v2.3

Sascha

Заместитель Администратора
Команда форума
Администратор
Регистрация
9 Май 2015
Сообщения
1,071
Баллы
155
Возраст
51

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

v2.3 now includes a new free service for geocoding and directions in addition to the existing supported directions services from Azure, Bing, Google, Here and MapBox.



OpenRouteService



TMS Software Delphi  Components


The

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

API service provides geocoding, reverse geocoding and directions free of charge. It does, however, require the use of an API key. This service can be used in combination with all supported mapping services in

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

. Specifically in combination with the OpenLayers mapping service this is a worthwhile free alternative to comparable paying services.


Geocoding



A geocoding request converts a text address to a latitude & longitude coordinate. The coordinate can then be used to display a location on the map.

TMS Software Delphi  Components


With the following code we are going to look up the location of "Baker Street, London" and display it on the center of the map with a marker and a title that contains the address.
Note that this example uses the asynchronous method with a callback.

procedure TForm1.Button1Click(Sender: TObject);
var
Item: TTMSFNCGeocodingItem;
begin
TMSFNCGeocoding1.APIKey := 'abc123';
TMSFNCGeocoding1.Service := gsOpenRouteService;
TMSFNCGeocoding1.GetGeocoding('Baker Street, London',
procedure(const ARequest: TTMSFNCGeocodingRequest; const ARequestResult: TTMSFNCCloudBaseRequestResult)
begin
if (ARequestResult.Success) and (ARequest.Items.Count > 0) then
begin
Item := ARequest.Items[0];

TMSFNCMaps1.BeginUpdate;
TMSFNCMaps1.SetCenterCoordinate(Item.Coordinate.ToRec);
TMSFNCMaps1.AddMarker(Item.Coordinate.ToRec, Item.Address);
TMSFNCMaps1.EndUpdate;
end;
end
);
end;



Reverse Geocoding


A reverse geocoding request converts a latitude & longitude coordinate to a text address. The text address can then be used to display an address associated with a location on the map.

TMS Software Delphi  Components


With the following code we are going to track a click on the map, retrieve the address for that location and display it on the map with a marker and a title that contains the address
Note that this example uses the synchronous method that provides an immediate result without a callback.


procedure TForm1.TMSFNCMaps1MapClick(Sender: TObject; AEventData: TTMSFNCMapsEventData);
var
Address: string;
begin
TMSFNCGeocoding1.APIKey := 'abc123';
TMSFNCGeocoding1.Service := gsOpenRouteService;
Address := TMSFNCGeocoding1.GetReverseGeocodingSync(AEventData.Coordinate.ToRec);

TMSFNCMaps1.BeginUpdate;
TMSFNCMaps1.SetCenterCoordinate(AEventData.Coordinate.ToRec);
TMSFNCMaps1.AddMarker(AEventData.Coordinate.ToRec, Address);
TMSFNCMaps1.EndUpdate;
end;




Directions




A directions request provides step by step directions between a start and end location. The directions data can then be used to display a route on the map. Additional options can be configured for the directions request, including: waypoints, alternative routes and language.

TMS Software Delphi  Components


With the following code we are going to retrieve driving directions between New York and Philadelphia. On the map, a marker is displayed at both the start and end location, a polyline displays the route and a label displays the distance and duration of the route.
In the TListBox on the step by step directions are displayed for each step in the route directions.


procedure TForm1.Button1Click(Sender: TObject);
var
cStart, cEnd: TTMSFNCMapsCoordinateRec;
begin
cStart.Latitude := 40.68295;
cStart.Longitude := -73.9708;
cEnd.Latitude := 39.990821;
cEnd.Longitude := -75.168428;

TMSFNCDirections1.APIKey := 'abc123';
TMSFNCDirections1.Service := dsOpenRouteService;
TMSFNCDirections1.GetDirections(cStart, cEnd,
procedure(const ARequest: TTMSFNCDirectionsRequest; const ARequestResult: TTMSFNCCloudBaseRequestResult)
var
it: TTMSFNCDirectionsItem;
I: Integer;
p: TTMSFNCOpenLayersPolyline;
Hours, Minutes: string;
begin
TMSFNCOpenLayers1.ClearPolylines;
ListBox1.Clear;

if ARequestResult.Success then
begin
if ARequest.Items.Count > 0 then
begin
TMSFNCOpenLayers1.BeginUpdate;
it := ARequest.Items[0];

TMSFNCOpenLayers1.AddMarker(it.Legs[0].StartLocation.ToRec, 'New York', DEFAULTWAYPOINTMARKER);
TMSFNCOpenLayers1.AddMarker(it.Legs[0].EndLocation.ToRec, 'Philadelphia', DEFAULTENDMARKER);

Hours := IntToStr(Round(it.Duration / 60) div 60);
Minutes := IntToStr(Round(it.Duration / 60) mod 60);

p := TTMSFNCOpenLayersPolyline(TMSFNCOpenLayers1.AddPolyline(it.Coordinates.ToArray));
p.StrokeColor := gcBlue;
p.StrokeOpacity := 0.5;
p.StrokeWidth := 5;
p.&Label.Text := FloatToStr(Round(it.Distance / 1000)) + ' km, ' + Hours + 'h ' + Minutes + ' min';

TMSFNCOpenLayers1.ZoomToBounds(it.Coordinates.Bounds.ToRec);
TMSFNCOpenLayers1.EndUpdate;

ListBox1.Clear;
for I := 0 to it.Steps.Count - 1 do
begin
ListBox1.Items.Add(it.Steps.Instructions)
end;
end;
end;
end
);
end;




Available Now


The

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

v2.3 update is available now for Delphi & Visual Studio Code (with

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

). You can

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

the latest version and start using the new features right away!




Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх