如果用xe6自带的LocationSensor控件,默认优先使用网络位置,网络位置定位精度不准确,不能满足高精度定位的要求。但xe6自带的LocationSensor控件不能指定网络定位优先还是GPS定位优先,如果调用java API是可以指定优先使用GPS定位,以下代码经实测证实是可以直接指定GPS定位的。
 
uses Androidapi.JNI.Location, Androidapi.JNIBridge, Androidapi.JNI.JavaTypes, 
  Androidapi.JNI.Os,FMX.Helpers.Android,Androidapi.JNI.GraphicsContentViewText;
 
type
  TLocationListener = class;
  TForm1 = class(TForm)
 
  . . . . . .
 
  private
    { Private declarations }
    FLocationManager : JLocationManager;
    locationListener : TLocationListener;
  public
    destructor Destroy; override;
    { Public declarations }
    procedure onLocationChanged(location: JLocation);
  end;
  //Sensore GPS
  TLocationListener = class(TJavaLocal, JLocationListener)
  private
    [weak]
    FParent : TForm1;
  public
    constructor Create(AParent : TForm1);
    procedure onLocationChanged(location: JLocation); cdecl;
    procedure onProviderDisabled(provider: JString); cdecl;
    procedure onProviderEnabled(provider: JString); cdecl;
    procedure onStatusChanged(provider: JString; status: Integer; extras: JBundle); cdecl;
  end;
 
. . . . .
 
constructor TLocationListener.Create(AParent: TForm1);
begin
  inherited Create;
  FParent := AParent;
end;
 
procedure TLocationListener.onLocationChanged(location: JLocation);
begin
  FParent.onLocationChanged(location);
end;
 
procedure TLocationListener.onProviderDisabled(provider: JString);
begin
end;
 
procedure TLocationListener.onProviderEnabled(provider: JString);
begin
end;
 
procedure TLocationListener.onStatusChanged(provider: JString; status: Integer; extras: JBundle);
begin
end;
 
destructor TForm1.Destroy;
begin
  if Assigned(locationListener) then
    FLocationManager.removeUpdates(locationListener);
  inherited;
end;
 
procedure TForm1.onLocationChanged(location: JLocation);//位置发生变化时,显示经、纬度
begin
  if Assigned(location) then
  begin
     //variabili da recuperare dal sensore
     Label4.Text := location.getLatitude.ToString;
     Label5.Text := location.getLongitude.ToString;
     Label6.Text := location.getAltitude.ToString;
     Label8.Text := location.getSpeed.ToString;
     Label10.Text := location.getTime.ToString;
  end;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
var LocationManagerService: JObject;
    location : JLocation;
begin 
  if not Assigned(FLocationManager) then
  begin
    LocationManagerService := SharedActivityContext.getSystemService(TJContext.JavaClass.LOCATION_SERVICE);
    FLocationManager := TJLocationManager.Wrap((LocationManagerService as ILocalObject).GetObjectID);
    if not Assigned(locationListener) then locationListener := TLocationListener.Create(self);
    FLocationManager.requestLocationUpdates(TJLocationManager.JavaClass.GPS_PROVIDER, 1000, 0, locationListener, TJLooper.JavaClass.getMainLooper);
      // 监听状态
      // 绑定监听,有4个参数
      // 参数1,设备:有GPS_PROVIDER和NETWORK_PROVIDER两种
      // 参数2,位置信息更新周期,单位毫秒
      // 参数3,位置变化最小距离:当位置距离变化超过此值时,将更新位置信息
      // 参数4,监听
      // 备注:参数2和3,如果参数3不为0,则以参数3为准;参数3为0,则通过时间来定时更新;两者为0,则随时刷新
      // 1秒更新一次,或最小位移变化超过1米更新一次;
      // 注意:此处更新准确度非常低,推荐在service里面启动一个Thread,在run中sleep(10000);然后执行handler.sendMessage(),更新位置
  end;
 FLocationManager.isProviderEnabled(TJLocationManager.JavaClass.GPS_PROVIDER);
  FLocationManager.isProviderEnabled(TJLocationManager.JavaClass.NETWORK_PROVIDER);
  onLocationChanged(location);
end

delphi xe6 调用java GPS的方法的更多相关文章

  1. oracle调用JAVA类的方法

    导入jar包 在oracle中导入需要的jar包,我们把编辑好的java类打成jar包,直接在oarcle里面写简单的调用就可以了,  1.操作系统需要拥有支持loadjava命令的jdk.  2.加 ...

  2. Delphi动态调用Java的WebService 转

    Delphi动态调用Java的WebService —— 基于“Axis2发布WebService例子(HelloWorld)” uses ComObj; var WsObject: Variant; ...

  3. 如何在Mybatis的xml文件调用java类的方法

    在mybatis的映射xml文件调用java类的方法:使用的是OGNL表达式,表达式格式为:${@prefix@methodName(传递参数名称)} 1.如下代码所示:方法必须为静态方法:以下我只是 ...

  4. Delphi XE6调用javascript

    原文地址:Example of using JavaScript for Google maps in the Delphi XE6   XE6的TWebBrowser新增了EvaluateJavaS ...

  5. Delphi XE7调用Java Class,JAR

    Delphi XE5,XE6需要用户手工编译并将Classes.Dex加入到包中,不过Delphi XE7可以省掉这些工作了. 如何在XE7中调用Java,具体步骤如下: 1.将jar文件添加到XE7 ...

  6. C#实现调用Java类中方法

    基本思路: 用C#实现调用Java编写的类中的方法:重点是将Java编写的程序打包成Jar,然后使用开源工具IKVM将其转化成DLL控件,在.NET环境下调用. 分为以下步骤: 1.下载JDK6(注: ...

  7. .NET调用JAVA的WebService方法

    调用WebService,最简单的办法当然是直接添加WEB引用,然后自动产生代理类,但是在调用JAVA的WebService时并没有这么简单,特别是对于SoapHeader的处理,在网上也有相关资料, ...

  8. .Net调用Java的实现方法

    一. IKVM 1.1下载配置IKVM 1.1.1. 下载路径 http://www.ikvm.net/index.html 1.1.2. 设置路径 解压ikvm-0.42.0.3.zip,并将%IK ...

  9. Delphi调用Java类

    1. Delphi XE7调用Java Class,JAR http://www.th7.cn/Program/delphi/201409/277888.shtml ZC: 文章中又提到:http:/ ...

随机推荐

  1. LeetCode Distribute Candies

    原题链接在这里:https://leetcode.com/problems/distribute-candies/#/description 题目: Given an integer array wi ...

  2. Thinkphp 自定义404页面

    一. 手册->调试->异常处理 在公共config.php 中加入: 'TMPL_EXCEPTION_FILE' => '/Public/404.html', //访问不存在的跳转 ...

  3. Visualforce入门第一篇_2017.3.1

    什么是Visualforce??   Visualforce是Forcce.com平台上的试图控制技术,结构与标记与HTML非常相似.Visualforce页面可以显示从数据库或者Web服务器得到的数 ...

  4. 命令"service 服务名 restart" 与 "service 服务名 reload"的区别

    由于今天用到了service nginx reload 和 service nginx restart,说说他俩的区别吧: reload:不间断服务重启,就像一张网页上面的刷新按钮一样. restar ...

  5. (转)Dynamic Web project转成Maven项目

    本文转载自:http://my.oschina.net/twosnail/blog/369125 1.新建Dynamic Web Project 1.File -> New -> Othe ...

  6. java继承如何理解呢??

    总结:我把他弄的无语了.他是诺基亚公司的软件开发师,大学毕业就可以进那么好的公司.实力 package com.bc; //普通类 class yt { public void price() { S ...

  7. 2018年长沙理工大学第十三届程序设计竞赛 H数学考试

    链接:https://www.nowcoder.com/acm/contest/96/H来源:牛客网 数学考试 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  8. Winsock 示例

    #include "stdafx.h" #include <Windows.h> #include <iostream> #pragma comment(l ...

  9. createprocess并行运算

    #include "stdafx.h"#include "windows.h"#include <iostream> using namespace ...

  10. Solaris Tips: Repairing the Boot Archive (ZT)

    http://www.seedsofgenius.net/solaris/solaris-tips-repairing-the-boot-archive 注意以下是系统盘非镜像情况下的操作,如果系统盘 ...