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之数组

Delphi webbrowser1 设置获取编码

Delphi xe5-android开发 目录结构

Delphi memo1双击选中的文字内容

Delphi 用文件流读取文本文件字符串的方法

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

Delphi 从给定字符串中截取n个字节的字符(解决汉字截取乱码问题)

Delphi 判断端口(port)是否被占用

Delphi 调用ie隐藏的命令

Delphi 提高进程自身权限

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



打赏

取消

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

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

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

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

评论

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