
procedure TForm1.Button1Click(Sender: TObject);
var
LocationManagerService: JObject;
iter : JIterator;
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, 10000, 10, locationListener,
TJLooper.JavaClass.getMainLooper);
end;
iter := FLocationManager.GetAllProviders.Iterator;
ListBox1.Clear;
while iter.hasNext do
begin
ListBox1.Items.Add(JStringToString(iter.next.ToString));
end;
CheckBox1.IsChecked := FLocationManager.isProviderEnabled(TJLocationManager.JavaClass.GPS_PROVIDER);
CheckBox2.IsChecked := FLocationManager.isProviderEnabled(TJLocationManager.JavaClass.NETWORK_PROVIDER);
location := FLocationManager.getLastKnownLocation(TJLocationManager.JavaClass.GPS_PROVIDER);
onLocationChanged(location);
end;
Download our mirror of the Android GPS JNI project demo with Delphi XE7 Firemonkey support.
Update: For Delphi 10.2 Tokyo you should check out the code for doing this on StackOverFlow.
Thanks!
the “location” variable always NIL in delphi berlin 10 update 2, how to solve this problem ?
i’am using android 6 and nougat