博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android实例-LocationSensor位置传感器(XE8+小米2)
阅读量:7201 次
发布时间:2019-06-29

本文共 3297 字,大约阅读时间需要 10 分钟。

 

 

结果:

1.启动后有时会闪退,后来重新做的工程就好了。原因不明(可能与地理反码有关)。

2.原文是用的GOOGLE地图显示位置,但在咱们这里好像不行,改为百度,但百度用的是HTML文件。太麻烦了,大家自己看百度API吧。

3.打开二个权限,不过我看了一下工程自动就是打上对号的(Access coarse location、Access fine location)。 

 

相关资料:

官网地址  http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_Location_Sensors_(iOS_and_Android)

 

实例代码:

1 unit Unit1; 2  3 interface 4  5 uses 6   System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7   FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Sensors, 8   System.Sensors.Components, FMX.WebBrowser, FMX.Controls.Presentation, 9   FMX.StdCtrls;10 11 type12   TForm1 = class(TForm)13     Button1: TButton;14     WebBrowser1: TWebBrowser;15     LocationSensor1: TLocationSensor;16     Label1: TLabel;17     Label2: TLabel;18     Label3: TLabel;19     Label4: TLabel;20     Label5: TLabel;21     Label6: TLabel;22     Label7: TLabel;23     Label8: TLabel;24     Label9: TLabel;25     Label10: TLabel;26     Label11: TLabel;27     Label12: TLabel;28     Label13: TLabel;29     procedure Button1Click(Sender: TObject);30     procedure LocationSensor1LocationChanged(Sender: TObject; const OldLocation,31       NewLocation: TLocationCoord2D);32   private33     {
Private declarations }34 FGeocoder: TGeocoder;//定义地理编码对象35 procedure OnGeocodeReverseEvent(const Address: TCivicAddress);//定义地理编码事件36 public37 {
Public declarations }38 end;39 40 var41 Form1: TForm1;42 43 implementation44 45 {
$R *.fmx}46 {
$R *.NmXhdpiPh.fmx ANDROID}47 48 procedure TForm1.Button1Click(Sender: TObject);49 begin50 LocationSensor1.Active := True;51 end;52 53 procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;54 const OldLocation, NewLocation: TLocationCoord2D);55 var56 URLString: String;57 begin58 //显示经纬度59 Label2.Text := Format('纬度:%2.6f', [NewLocation.Latitude]);60 Label3.Text := Format('经度:%2.6f', [NewLocation.Longitude]);61 //地图显示位置62 // URLString := Format('https://maps.google.com/maps?q=%s,%s',63 // [Format('%2.6f', [NewLocation.Latitude]), Format('%2.6f', [NewLocation.Longitude])]);64 // WebBrowser1.Navigate(URLString);65 //地理编码功能66 if not Assigned(FGeocoder) then67 begin68 if Assigned(TGeocoder.Current) then69 FGeocoder := TGeocoder.Current.Create;70 if Assigned(FGeocoder) then71 FGeocoder.OnGeocodeReverse := OnGeocodeReverseEvent;72 end;73 if Assigned(FGeocoder) and not FGeocoder.Geocoding then74 FGeocoder.GeocodeReverse(NewLocation);75 end;76 77 //地理编码事件具体实现78 procedure TForm1.OnGeocodeReverseEvent(const Address: TCivicAddress);79 begin80 label4.Text := Format('行政区:%s', [Address.AdminArea]);81 label5.Text := Format('国家代码:%s', [Address.CountryCode]);82 label6.Text := Format('国家名称:%s', [Address.CountryName]);83 label7.Text := Format('特征名称:%s', [Address.FeatureName]);84 label8.Text := Format('地区:%s', [Address.Locality]);85 label9.Text := Format('邮政编码:%s', [Address.PostalCode]);86 label10.Text := Format('分行政区:%s', [Address.SubAdminArea]);87 label11.Text := Format('分地区:%s', [Address.SubLocality]);88 label12.Text := Format('分大街:%s', [Address.SubThoroughfare]);89 label13.Text := Format('大街:%s', [Address.Thoroughfare]);90 end;91 92 end.

 

转载地址:http://pewum.baihongyu.com/

你可能感兴趣的文章
YII2.0 高级模板-添加自定义模板
查看>>
Cisco 思科网络设备模拟器 GNS3 使用指南
查看>>
Android版添加phonegap--百度api定位插件教程
查看>>
arm c中字节对齐
查看>>
51cto我来了
查看>>
Linux的Web服务基础概念
查看>>
LNMP搭建
查看>>
RecyclerView的基础使用
查看>>
nginx学习笔记
查看>>
安装PHP扩展eaccelerator加速器
查看>>
SVN 学习
查看>>
SmartSVN设置ignoreList
查看>>
ios-网址中的中文或者非法字符转换
查看>>
自定义通知与系统通知的学习(详解)
查看>>
[翻译]Selenium自动化测试框官网翻译-目录
查看>>
Application tried to present modal view controller on itself
查看>>
再见2011,奋斗2012
查看>>
菜鸟学Linux 第051篇笔记 web-server, http
查看>>
我的友情链接
查看>>
Windows Server 2008遗忘管理员密码后的解决方法
查看>>