Delphi Can
Locasyon açmıyor - Baskı Önizleme

+- Delphi Can (https://www.delphican.com)
+-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3)
+--- Forum: Mobil Platform - FireMonkey (FMX) (https://www.delphican.com/forumdisplay.php?fid=7)
+--- Konu Başlığı: Locasyon açmıyor (/showthread.php?tid=6262)



Locasyon açmıyor - barissagir - 07-09-2021

Selamün Aleykum 
Merhaba Arkadaşlar

Programımda 1 buton ve Edit var. 
Amacım butona tıklandığında Edit e Hangi şehirde olduğumu yazdırmak.

 uses
 FMX.DialogService
 {$IFDEF ANDROID}
 ,Androidapi.Helpers, Androidapi.JNI.JavaTypes, Androidapi.JNI.Os
 {$ENDIF}
 ;
procedure TForm1.Button1Click(Sender: TObject);
begin
LocationSensor1.Active := False;
{$IFDEF ANDROID}
   PermissionsService.RequestPermissions([JStringToString(TJManifest_permission.JavaClass.ACCESS_FINE_LOCATION)],
     procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
     begin
       if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
         { activate or deactivate the location sensor }
         LocationSensor1.Active := True
       else
       begin
         TDialogService.ShowMessage('Lokasyona izin verilmedi');
       end;
     end);
{$ENDIF}

LocationSensor1.Active:=True;
end;

procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
 const OldLocation, NewLocation: TLocationCoord2D);
begin
 try
   if not Assigned(FGeocoder) then
   begin
     if Assigned(TGeocoder.Current) then
       FGeocoder := TGeocoder.Current.Create;
     if Assigned(FGeocoder) then
       FGeocoder.OnGeocodeReverse := OnGeocodeReverseEvent;
   end;
 except
     Showmessage('Lokasyona ulaşılamıyor');
 end;

 // Translate location to address
 if Assigned(FGeocoder) and not FGeocoder.Geocoding then
   FGeocoder.GeocodeReverse(NewLocation);
end;


procedure TForm1.OnGeocodeReverseEvent(const Address: TCivicAddress);
begin
 Edit1.Text       := Address.AdminArea;
end;

Butona tıkladığımda izin alma geliyor.

Ancak telefondaki lokasyon  çalışmıyor.
Sonuç olarak bişey gelmiyor.

Ama Lokasyonu elle açtığımda butona basınca sonucu getiriyor.

Konum nasıl otomatik olarak çalışır.

Başka ne yapmam gerekir.
Şimdiden teşekkür ederim.