本文整理自网络,侵删。
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);beginend;将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 tmemo控件滚动条scrollbar末尾插入字符串一点都会闪烁的轻松实现
Delphi webbrowser控件的documentcomplete和downloadcomplete的区别
Delphi fdconnection执行sql execsql
更多相关阅读请进入《Delphi》频道 >>