zoukankan      html  css  js  c++  java
  • GOOGLE定位

    GOOGLE定位

    /// <author>cxg 2018-3-27</author>

    unit umap;

    interface

    uses
    System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
    FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
    FRM_BASS_MAIN, FMX.Effects, FMX.Controls.Presentation, FMX.Objects, System.Sensors,
    FMX.ListBox, FMX.Layouts, System.Sensors.Components, FMX.WebBrowser;

    type
    Tfmap = class(TFrame_Base_Main)
    ToolBar1: TLayout;
    Button1: TButton;
    WebBrowser1: TWebBrowser;
    Layout1: TLayout;
    ListBox1: TListBox;
    ListBoxItemLatitude: TListBoxItem;
    ListBoxItemLongitude: TListBoxItem;
    ListBox2: TListBox;
    ListBoxItemAdminArea: TListBoxItem;
    ListBoxItemCountryCode: TListBoxItem;
    ListBoxItemCountryName: TListBoxItem;
    ListBoxItemFeatureName: TListBoxItem;
    ListBoxItemLocality: TListBoxItem;
    ListBoxItemPostalCode: TListBoxItem;
    ListBoxItemSubAdminArea: TListBoxItem;
    ListBoxItemSubLocality: TListBoxItem;
    ListBoxItemSubThoroughfare: TListBoxItem;
    ListBoxItemThoroughfare: TListBoxItem;
    LocationSensor1: TLocationSensor;
    procedure Button1Click(Sender: TObject);
    procedure LocationSensor1LocationChanged(Sender: TObject; const OldLocation, NewLocation: TLocationCoord2D);
    private
    { Private declarations }
    FGeocoder: TGeocoder;
    procedure OnGeocodeReverseEvent(const Address: TCivicAddress);
    procedure Geocoder(location: TLocationCoord2D);
    public
    { Public declarations }
    Procedure Unitialize; override;
    end;

    var
    fmap: Tfmap;

    implementation

    {$R *.fmx}

    { TFrame_Base_Main2 }

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

    procedure Tfmap.Geocoder(location: TLocationCoord2D);
    begin
    // 利用 TGeocoder进行地名解析
    //建立TGeocode实像,并为之设置事件代码
    if not Assigned(FGeocoder) then
    begin
    if Assigned(TGeocoder.Current) then
    FGeocoder := TGeocoder.Current.Create;
    if Assigned(FGeocoder) then
    FGeocoder.OnGeocodeReverse := OnGeocodeReverseEvent;
    end;

    //转换成地名
    if Assigned(FGeocoder) and not FGeocoder.Geocoding then
    FGeocoder.GeocodeReverse(Location);
    end;

    procedure Tfmap.LocationSensor1LocationChanged(Sender: TObject; const OldLocation, NewLocation: TLocationCoord2D);
    var
    URLString: string;
    LSettings: TFormatSettings;
    LDecSeparator: Char;
    begin
    LDecSeparator := FormatSettings.DecimalSeparator;
    LSettings := FormatSettings;
    try
    FormatSettings.DecimalSeparator := '.';
    // 显示当前位置
    ListBoxItemLatitude.ItemData.Text := Format('纬度: %2.6f', [NewLocation.Latitude]);
    ListBoxItemLongitude.ItemData.Text := Format('经度: %2.6f', [NewLocation.Longitude]);
    // 用 Google Maps显示
    URLString := Format('https://maps.google.com/maps?q=%2.6f,%2.6f', [NewLocation.Latitude, NewLocation.Longitude]);
    finally
    FormatSettings.DecimalSeparator := LDecSeparator;
    end;

    { and track the location via Google Maps }
    WebBrowser1.Navigate(URLString);

    Geocoder(NewLocation);
    end;

    procedure Tfmap.OnGeocodeReverseEvent(const Address: TCivicAddress);
    begin
    ListBoxItemSubAdminArea.ItemData.Text := Format('子行政区: %s', [Address.SubAdminArea]);
    ListBoxItemAdminArea.ItemData.Text := Format('省州: %s', [Address.AdminArea]);
    ListBoxItemCountryCode.ItemData.Text := Format('国家编码: %s', [Address.CountryCode]);
    ListBoxItemCountryName.ItemData.Text := Format('国家名称: %s', [Address.CountryName]);
    ListBoxItemFeatureName.ItemData.Text := Format('详细地址: %s', [Address.FeatureName]);
    ListBoxItemSubLocality.ItemData.Text := Format('区县: %s', [Address.SubLocality]);
    ListBoxItemLocality.ItemData.Text := Format('城市: %s', [Address.Locality]);
    ListBoxItemPostalCode.ItemData.Text := Format('邮政编码: %s', [Address.PostalCode]);
    ListBoxItemSubThoroughfare.ItemData.Text := Format('子街道: %s', [Address.SubThoroughfare]);
    ListBoxItemThoroughfare.ItemData.Text := Format('街道: %s', [Address.Thoroughfare]);
    end;

    procedure Tfmap.Unitialize;
    begin
    inherited;
    FGeocoder.DisposeOf;
    end;

    end.

  • 相关阅读:
    pyhton 小技巧
    scikit-learn K近邻法类库使用小结
    机器学习加速方法
    Virtual box安装回退的一系列可能的原因及解决办法
    Linux 定时任务
    Redis 操作命令
    在linux下安装并运行scrapyd
    同步/异步 异步回调 协成 线程队列
    Python常用的标准库以及第三方库有哪些?
    Flask 知识点
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/8742755.html
Copyright © 2011-2022 走看看