红鱼儿

优化CC高德地图定位方法

作者没有为申请定位增加权限处理,这样要在外部申请权限。我改成这样:

procedure TCCAMap.StartLocation();
begin

{$IFDEF ANDROID}
  PermissionsService.RequestPermissions([JStringToString(TJManifest_permission.JavaClass.ACCESS_COARSE_LOCATION),
                                         JStringToString(TJManifest_permission.JavaClass.ACCESS_FINE_LOCATION),
                                         JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE),
                                         JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE)
                                        ],
{$IF CompilerVersion >= 35} // Delphi 11
    procedure(const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray)
{$ELSE}
  procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
{$ENDIF}
  begin
    if (Length(AGrantResults) = 4) and
       (AGrantResults[0] = TPermissionStatus.Granted) and
       (AGrantResults[1] = TPermissionStatus.Granted) and
       (AGrantResults[2] = TPermissionStatus.Granted) and
       (AGrantResults[3] = TPermissionStatus.Granted) then
    begin
      // 必须有读写权限再初始化.
      FJAMap.StartLocation;
    end;
  end);
{$ENDIF}

end;

 

posted on 2024-07-25 17:24  红鱼儿  阅读(85)  评论(0编辑  收藏  举报