Delphi Android / iOS应用程序中使用TGeocoder类进行反向地理编码(从位置信息中获取地址)


本文整理自网络,侵删。

 
Delphi有一个称为TGeocoder的类,用于处理地理编码和反向地理编码。
它可能没有引起注意,因为它没有在工具选项板中注册。

介绍如何使用“ TGeocoder ”从位置信息获取地址。

使用“ TLocationSensor ”获得位置信息。
如果TLocationSensor的Active属性设置为True,则可以通过OnLocationChanged事件获取位置信息。

procedure TForm1.Button1Click(Sender: TObject);
begin
  LocationSensor1.Active := True;
end;

procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
  const OldLocation, NewLocation: TLocationCoord2D);
begin
end;
将TGeocoder变量添加到私有字段。

private
  FGeocoder: TGeocoder;
反向地理编码过程完成后,TGeocoder会引发 OnGeocodeReverse事件。

添加一个方法来处理OnGeocodeReverse事件。

procedure OnGeocodeReverseEvent(const Address: TCivicAddress);
在窗体的构造函数中执行初始设置。

procedure TForm1.FormCreate(Sender: TObject);
begin
  FGeocoder := TGeocoder.Current.Create;
  FGeocoder.OnGeocodeReverse := OnGeocodeReverseEvent;
end;
TLocationSensor在OnLocationChanged事件获取的位置信息TGeocoder并与反向地理编码。

procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
  const OldLocation, NewLocation: TLocationCoord2D);
begin
  LocationSensor1.Active := False;
  FGeocoder.GeocodeReverse(NewLocation);
end;
显示通过反向地理编码获得的地址。

procedure TForm1.OnGeocodeReverseEvent(const Address: TCivicAddress);
begin
  TThread.Synchronize(TThread.CurrentThread,
    procedure
    begin
      Memo1.Lines.Clear;
      Memo1.Lines.Add('国家代码:' + Address.CountryCode);
      Memo1.Lines.Add('国名:' + Address.CountryName);
      Memo1.Lines.Add('管理?I域:' + Address.AdminArea);
      Memo1.Lines.Add('管理区域:' + Address.SubAdminArea);
      Memo1.Lines.Add('区域名:' + Address.Locality);
      Memo1.Lines.Add('子区域:' + Address.SubLocality);
      Memo1.Lines.Add('街道:' + Address.SubThoroughfare);
      Memo1.Lines.Add('街道:' + Address.Thoroughfare);
    end);
end;

//上面得翻译是用百度翻译得,将就下吧。

相关阅读 >>

Delphi xe(indy10)tidbytes转ansistring的实现

Delphi high 返回数组下标的最大值

Delphi 一行一行读取txt文件

Delphi 微信公众平台 Delphi sdk

Delphi tmemo控件滚动条scrollbar末尾插入字符串一点都会闪烁的轻松实现

Delphi 2009 之 tedit 加强的功能

Delphi字符串、数组操作函数

Delphi webbrowser控件的documentcomplete和downloadcomplete的区别

Delphi 从dbgird中导出到excel

Delphi fdconnection执行sql execsql

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...