如何在 fusedlocationproviderclient.oncompletelistener() 中添加进度条?

     2023-04-14     19

关键词:

【中文标题】如何在 fusedlocationproviderclient.oncompletelistener() 中添加进度条?【英文标题】:How to add progressbar in fusedlocationproviderclient.oncompletelistener()? 【发布时间】:2020-07-20 13:06:06 【问题描述】:

我正在使用 fusedlocationproviderclient 来查找当前位置,但我希望进度条应该显示直到找到位置,但我不明白如何在 oncomplete() 方法中使用进度条 这是我的 fusedlocation 函数的代码。

progressBar = findViewById(R.id.homrprogressbar);
    progressBar.setIndeterminate(true);
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    if (checkPermissions()) 
        if (isLocationEnabled()) 
            mFusedLocationClient.getLastLocation().addOnCompleteListener(
                    new OnCompleteListener<Location>() 
                        @Override
                        public void onComplete(@NonNull Task<Location> task) 
                            progressBar.setVisibility(View.VISIBLE);
                            Location location = task.getResult();
                            if (location == null) 
                                requestNewLocationData();
                             else 
                                countryname = findcountry(location.getLatitude(), location.getLongitude());
                                if(countryname.equals("India")) 
                                    TypedArray allcountry = getResources().obtainTypedArray(R.array.indianews);
                                    String[] allcountryname = getResources().getStringArray(R.array.indianewsnames);
                                    String[] allcountryurls = getResources().getStringArray(R.array.indiahref);
                                    newsModels = new ArrayList<>();
                                    for (int i = 0; i < allcountry.length(); i++) 
                                        NewsModel newsModel = new NewsModel(allcountry.getResourceId(i, 0), allcountryname[i], allcountryurls[i]);
                                        newsModels.add(newsModel);
                                    
                                    Singleton.getConstant().addNewsModel(newsModels);
                                    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                                    fragmentTransaction.replace(R.id.frame_layout, homeFragment);
                                    fragmentTransaction.commit();
                                    binding.bottmNav.getMenu().findItem(R.id.location).setTitle("India");
                                    binding.bottmNav.getMenu().findItem(R.id.home1).setChecked(true);
                                    progressBar.setVisibility(View.GONE);

                                
                            
                        
                    
            );
         else 
            Toast.makeText(this, "Turn on location", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        
     else 
        requestPermissions();
    

【问题讨论】:

把progressBar.setVisibility(View.VISIBLE);在 if (isLocationEnabled()) 下 【参考方案1】:

progressBar.setVisibility(View.VISIBLE);放在if (isLocationEnabled())下面

【讨论】:

FusedLocationProvider 始终返回 null Location 对象

】FusedLocationProvider始终返回nullLocation对象【英文标题】:FusedLocationProvideralwaysreturnsnullLocationobject【发布时间】:2022-01-2116:12:15【问题描述】:我已经尝试了无数的FusedLocationProviderClient实现,我在互联网上找到并使用文档,但每... 查看详情

FusedLocationProvider 有时会给出错误的位置

】FusedLocationProvider有时会给出错误的位置【英文标题】:FusedLocationProvidergiveswronglocationsometimes【发布时间】:2019-08-2003:49:17【问题描述】:我正在使用FusedLocationProviderClient在前台服务中获取位置更新。经过几天的测试和观察,我... 查看详情

如何在 Service 类中使用 Fused Location Provider?

】如何在Service类中使用FusedLocationProvider?【英文标题】:HowcanIuseFusedLocationProviderinsideaServiceclass?【发布时间】:2016-07-1905:07:59【问题描述】:我需要在后台获取用户的位置,所以我尝试在我的Service类中使用FusedLocationProvider。我... 查看详情

HMS FusedLocationProvider 和 HuaweiMap 不工作

】HMSFusedLocationProvider和HuaweiMap不工作【英文标题】:HMSFusedLocationProviderandHuaweiMapisnotworking【发布时间】:2020-09-1206:17:54【问题描述】:我使用这个类为我的地图应用程序获取设备的当前位置。我将它与GooglePlayServices一起使用,它... 查看详情

使用 Google Play 服务我可以在离线模式下获取最新位置吗(FusedLocationProvider Api)

...使用GooglePlay服务我可以在离线模式下获取最新位置吗(FusedLocationProviderApi)【英文标题】:UsingGoogleplayservicecanigetlatestlocationinofflinemode(FusedLocationProviderApi)【发布时间】:2017-04-3016:12:09【问题描述】:使用谷歌播放服务,我们可... 查看详情

FusedLocationProvider 位置更新的单独类或服务?

】FusedLocationProvider位置更新的单独类或服务?【英文标题】:SeparateclassorServiceforFusedLocationProviderLocationupdates?【发布时间】:2018-11-1207:26:36【问题描述】:我目前有一个名为LocationCheck的类。publicclassSpeedCheck这里每3秒检索一次位... 查看详情

如何检测位置提供者? GPS 或网络提供商

...间】:2013-12-1911:33:19【问题描述】:我在我的应用中使用FusedLocationProvider进行位置更新。根据FusedLocationProvided文档,它使用所有可用资源(例如Wifi、GPS、手机信号塔等)来优化位置。但我想知道,有没有办法在位置更新 查看详情

使用 fusedLocationProvider.removeLocationUpdates (locationCallback) Android Studio 时出错

】使用fusedLocationProvider.removeLocationUpdates(locationCallback)AndroidStudio时出错【英文标题】:ErrorwhenusingfusedLocationProvider.removeLocationUpdates(locationCallback)AndroidStudio【发布时间】:2021-04-1308:37:50【问题描述】:我正在编写一个代码来捕获用 查看详情

Android:FusedLocationProvider,每隔几秒获取一次位置

】Android:FusedLocationProvider,每隔几秒获取一次位置【英文标题】:Android:FusedLocationProvider,getlocationeveryfewseconds【发布时间】:2019-11-2502:41:27【问题描述】:我正在制作一个应用程序来跟踪用户的位置并最终将其上传到Firebase服务... 查看详情

从 FusedLocationProvider(Google Play 服务)获取位置不会给出低于 10 米的准确度

】从FusedLocationProvider(GooglePlay服务)获取位置不会给出低于10米的准确度【英文标题】:GettingthelocationfromFusedLocationProvider(GooglePlayServices)doesn’tgiveaccuracybelow10meters【发布时间】:2018-10-1321:10:42【问题描述】:我们正在使用GooglePl... 查看详情

Re- JobScheduler 结合 FusedLocationProvider Api 经常给出空位置值

】Re-JobScheduler结合FusedLocationProviderApi经常给出空位置值【英文标题】:Re-JobSchedulercombinedwithFusedLocationProviderApioftensgivesnulllocationvalue【发布时间】:2018-03-2921:51:55【问题描述】:我有一个带有fusedLocationApi提供程序的jobScheduler。它... 查看详情

Fused Location Provider:有没有办法检查位置更新是不是失败?

】FusedLocationProvider:有没有办法检查位置更新是不是失败?【英文标题】:FusedLocationProvider:Isthereawaytocheckifalocationupdatefailed?FusedLocationProvider:有没有办法检查位置更新是否失败?【发布时间】:2016-06-2006:00:42【问题描述】:简... 查看详情

使用 Fused Location Provider 查找位置源

】使用FusedLocationProvider查找位置源【英文标题】:FindlocationsourceusingFusedLocationProvider【发布时间】:2013-09-0913:01:30【问题描述】:AFAIK,fusedlocationprovider可以根据不同的条件使用网络或gps数据。使用fusedlocationprovider获取位置后,... 查看详情

Fused Location Provider - 获得高精度

】FusedLocationProvider-获得高精度【英文标题】:FusedLocationProvider-gettinghighaccuracy【发布时间】:2019-09-0417:19:22【问题描述】:我正在尝试寻找一种方法来提高从GooglePlay服务的FusedLocationProvider获得的准确性。我正在测试一个使用Locat... 查看详情

融合位置提供程序 - onLocationChanged 停止被调用

...合位置提供程序-onLocationChanged停止被调用【英文标题】:FusedLocationProvider-onLocationChangedstopsgettingcalled【发布时间】:2016-09-2014:15:02【问题描述】:在我们的应用中,我们使用FusedLocationProvider(FLP)来跟踪位置。我们注意到,有时应... 查看详情

如何最准确地确定 Android 设备的位置?

...可以稍等片刻以确定位置(最多1-2分钟)。我一直在查看FusedLocationProvid 查看详情

Android 中的 Fused Location Provider 是不是仅在启用数据的情况下工作?

】Android中的FusedLocationProvider是不是仅在启用数据的情况下工作?【英文标题】:DoesFusedLocationProviderinAndroidWorkinonlyDataenabledsituation?Android中的FusedLocationProvider是否仅在启用数据的情况下工作?【发布时间】:2016-09-2802:44:43【问题... 查看详情

Fused Location Provider 是不是在没有 wifi 的情况下无法工作,还是只是不太准确?

】FusedLocationProvider是不是在没有wifi的情况下无法工作,还是只是不太准确?【英文标题】:DoesFusedLocationProvidernotworkwithoutwifiorisitjustlessaccurate?FusedLocationProvider是否在没有wifi的情况下无法工作,还是只是不太准确?【发布时间】... 查看详情