Android实例-LocationSensor位置传感器(XE8+小米2)

时间:2021-09-15 14:27:42

Android实例-LocationSensor位置传感器(XE8+小米2)

结果:

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)

实例代码:

 unit Unit1;

 interface

 uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Sensors,
System.Sensors.Components, FMX.WebBrowser, FMX.Controls.Presentation,
FMX.StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1: TWebBrowser;
LocationSensor1: TLocationSensor;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
procedure Button1Click(Sender: TObject);
procedure LocationSensor1LocationChanged(Sender: TObject; const OldLocation,
NewLocation: TLocationCoord2D);
private
{ Private declarations }
FGeocoder: TGeocoder;//定义地理编码对象
procedure OnGeocodeReverseEvent(const Address: TCivicAddress);//定义地理编码事件
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} procedure TForm1.Button1Click(Sender: TObject);
begin
LocationSensor1.Active := True;
end; procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);
var
URLString: String;
begin
//显示经纬度
Label2.Text := Format('纬度:%2.6f', [NewLocation.Latitude]);
Label3.Text := Format('经度:%2.6f', [NewLocation.Longitude]);
//地图显示位置
// URLString := Format('https://maps.google.com/maps?q=%s,%s',
// [Format('%2.6f', [NewLocation.Latitude]), Format('%2.6f', [NewLocation.Longitude])]);
// WebBrowser1.Navigate(URLString);
//地理编码功能
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(NewLocation);
end; //地理编码事件具体实现
procedure TForm1.OnGeocodeReverseEvent(const Address: TCivicAddress);
begin
label4.Text := Format('行政区:%s', [Address.AdminArea]);
label5.Text := Format('国家代码:%s', [Address.CountryCode]);
label6.Text := Format('国家名称:%s', [Address.CountryName]);
label7.Text := Format('特征名称:%s', [Address.FeatureName]);
label8.Text := Format('地区:%s', [Address.Locality]);
label9.Text := Format('邮政编码:%s', [Address.PostalCode]);
label10.Text := Format('分行政区:%s', [Address.SubAdminArea]);
label11.Text := Format('分地区:%s', [Address.SubLocality]);
label12.Text := Format('分大街:%s', [Address.SubThoroughfare]);
label13.Text := Format('大街:%s', [Address.Thoroughfare]);
end; end.

Android实例-LocationSensor位置传感器(XE8+小米2)的更多相关文章

  1. Android实例-操作摄像头(XE8+小米2)

    结果: 1.同样是照相,自己的程序设置为高质量时刷新慢,而小米手机的相机那真心反映快呀. 2.就算我设置为最高质量,可相片也没有小米手机的相片大.我最大是2000*1000,而小米可以做到3000*2 ...

  2. Android实例-手机震动(XE8+小米2)

    相关资料:http://blog.csdn.net/laorenshen/article/details/41148843 结果: 1.打开Vibrate权限为True. 2.规律震动我没感觉出来,有 ...

  3. Android实例-MotionSensor加速度(XE8+小米2)

    结果: 1. 实例代码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classe ...

  4. Android实例-消息框(XE8+小米2)

    方法一支持. 方法二与方法三都是三方单元,功能相同. 方法4与方法5报错,提示平台不支持. 第三方单元一: unit Android.JNI.Toast; // Java bridge class i ...

  5. Android实例-实现扫描二维码并生成二维码(XE8+小米5)

    相关资料: 第三方资料太大没法写在博文上,请下载CSDN的程序包. 程序包下载: http://download.csdn.net/detail/zhujianqiangqq/9657186 注意事项 ...

  6. Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(无图)

    注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYinYinQi ...

  7. Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)

    相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...

  8. 45个android实例源码

    分享45个android实例源码,很好很强大http://www.apkbus.com/android-20978-1-1.html andriod闹钟源代码http://www.apkbus.com ...

  9. 分享45个android实例源码,很好很强大

    分享45个android实例源码,很好很强大 http://www.apkbus.com/android-20978-1-1.html 分享45个android实例源码,很好很强大http://www ...

随机推荐

  1. windows+nginx+iis+redis+Task.MainForm构建分布式架构 之 (nginx+iis构建服务集群)

    本次要分享的是利用windows+nginx+iis+redis+Task.MainForm组建分布式架构,由标题就能看出此内容不是一篇分享文章能说完的,所以我打算分几篇分享文章来讲解,一步一步实现分 ...

  2. 【poj1018】 Communication System

    http://poj.org/problem?id=1018 (题目链接) 题意 要买n个产品,每个产品有m种价格和宽度(我也不知道翻译过来到底是什么?),设n个产品的宽度的最小值为B,n个产品的价格 ...

  3. 比较好的文件复制工具fastcopy和校验工具

    fastcopy http://ipmsg.org/tools/fastcopy.html.en extractfile --可以选用ADLER32计算模式,更快速.

  4. IIS express 7.5 设置默认文档

    在C:\Users\[电脑用户名]\Documents\IISExpress\config 下面有个applicationhost.config文件,打开文件找到<system.webServe ...

  5. socket对象放在一个datagridview的row的tag里面在拿出来 为什么是已释放

     socket对象放在一个datagridview的row的tag里面在拿出来 为什么是已释放 

  6. 制作U盘Win10 PE

    1.安装Windows ADK 下载地址 http://go.microsoft.com/fwlink/p/?LinkID=232339 2. 已管理员身份启动“部署和映像工具环境” 3.创建WinP ...

  7. idea调试代码跟踪到tomcat代码里面

    在POM.xml文件里面加上如下代码即可: <dependency> <groupId>org.apache.tomcat</groupId> <artifa ...

  8. PHP注释

    PHP支持C.C++和 Shell 脚本风格的注释. 单行注释 两个反斜线组成的单行注释 // 注释内容 一个井号组成的单行注释 # 注释内容 说明:PHP单行注释几乎用的都是//,很少使用#来注释内 ...

  9. 使用FormsAuthenticationTicket进行登陆验证

    if (账号密码验证成功) { //登陆成功 Session["User"] = account; FormsAuthenticationTicket ticket = new F ...

  10. myeclipse debug不显示变量值解决的方法

    依次点击打开mycelipse菜单选项:"Window" - "Preferences" - "Java" - "Editor&q ...