获取android 授权省略了,上调用GPS部份代码吧。
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);
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.Wrap
((LocationManagerService as ILocalObject).GetObjectID);
end;
//调用Java方法
// use the gps provider to get current lat, long and altitude
Location := fLocationManager.getLastKnownLocation
(tjlocationmanager.JavaClass.GPS_PROVIDER);
lat:=format('%2.6f',[location.getLatitude]);
lon:=format('%2.6f',[location.getLongitude]);
Alt := format('%2.6f',[location.getAltitude]);
edit1.Text:=lat;
edit2.Text:=lon;
end;
end.