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 无dll版下载者

Delphi抓取qq聊天窗口实例

Delphi 2009 之 tcategorypanelgroup[4]: height

Delphi 释放bitmap

Delphi 根据文件扩展名判断文件类型函数写法

Delphi中单独编译pas生成dcu文件

Delphi 获取dll文件的函数列表

Delphi system.sysutils.tmarshaller 与 system.tmarshal

Delphi 文件/流的加密解密方法

download 和 http downloader 源码

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



打赏

取消

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

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

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

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

评论

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