先上源码,在解释。
implementation
uses androidapi.jni.JavaTypes, androidapi.jni.Location, FMX.helpers.android,
androidapi.jni.GraphicsContentViewText, androidapi.jnibridge;
// context在android的content.context包
// ILocalObject在androidapi.jnibridge里
// sharedActivitycontext在fmx.helpers里
{$R *.fmx}
// 用android的地理GPS定位函数
procedure TForm1.Button1Click(Sender: TObject);
const
LGoogleMapURL: string = 'https://maps.google.com/maps?q=%s,%s&output=embed';
var
LocationManagerService: JObject;
Location: JLocation;
fLocationManager: JLocationManager;
Lat: string;
Lon: string;
Alt: string;
begin
if not assigned(fLocationManager) then
begin
//获得Java对象
LocationManagerService := sharedActivitycontext.getSystemService
(TJcontext.JavaClass.LOCATION_SERVICE);
// 获得对象的java实例
fLocationManager := tjlocationmanager.W

这篇博客介绍了如何利用Delphi XE5通过JNI接口调用Java服务来实现在Android设备上的GPS地理定位功能,提供了一段源代码作为实现示例。
最低0.47元/天 解锁文章
671





