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.

  • 相关阅读:
    Android 编程下 Eclipse 恢复被删除的文件
    Android 编程下背景图片适配工具类
    Android 编程下 Managing Your App's Memory
    Android 编程下代码之(QQ消息列表滑动删除)
    Android 编程下 Canvas and Drawables
    Android 编程下 AlarmManager
    Android 编程下去除 ListView 上下边界蓝色或黄色阴影
    Java 编程下字符串的 16 位、32位 MD5 加密
    C#枚举类型和int类型相互转换
    MVC和普通三层架构的区别
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/8742755.html
Copyright © 2011-2022 走看看