第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

getLastKnownLocation返回null

getLastKnownLocation返回null

慕勒3428872 2019-10-09 16:25:37
我已經(jīng)閱讀了有關(guān)此問題的一些問題,但并沒有找到我需要的答案。因此,情況是我已經(jīng)設(shè)置了地圖,并且想要獲取當(dāng)前的GPS位置。我檢查過我的變量不是NULL,但是我的結(jié)果是:getLastKnownLocation(provider, false);雖然給我null,所以這是我需要幫助的地方。我已經(jīng)添加了對(duì)COARSE + FINE位置的權(quán)限。但是我通常會(huì)禁用手機(jī)的各種網(wǎng)絡(luò)數(shù)據(jù),因?yàn)槲覍?duì)手機(jī)賬單中不可預(yù)測(cè)的數(shù)據(jù)流費(fèi)用感到不滿意。因此,此測(cè)試僅啟用并連接了WiFi。為了使之成為可能,我還需要啟用更多功能嗎?我認(rèn)為WiFi應(yīng)該足夠了嗎?
查看完整描述

3 回答

?
瀟瀟雨雨

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊

使用此方法獲取最近的已知位置:


LocationManager mLocationManager;

Location myLocation = getLastKnownLocation();


private Location getLastKnownLocation() {

    mLocationManager = (LocationManager)getApplicationContext().getSystemService(LOCATION_SERVICE);

    List<String> providers = mLocationManager.getProviders(true);

    Location bestLocation = null;

    for (String provider : providers) {

        Location l = mLocationManager.getLastKnownLocation(provider);

        if (l == null) {

            continue;

        }

        if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {

            // Found best last known location: %s", l);

            bestLocation = l;

        }

    }

    return bestLocation;

}


查看完整回答
反對(duì) 回復(fù) 2019-10-09
?
慕的地10843

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊

試試這個(gè)對(duì)我有用:-


LocationManager mLocationManager;

Location myLocation = getLastKnownLocation();


        private Location getLastKnownLocation() {

            Location oldLoc;

            while (true){

                oldLoc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                if (oldLoc == null){

                    continue;

                }

                else {

                    break;

                }

            }

            return oldLoc;

        }

您可以使用NETWORK_PROVIDER代替GPS_PROVIDER以獲得更快的結(jié)果。

查看完整回答
反對(duì) 回復(fù) 2019-10-09
  • 3 回答
  • 0 關(guān)注
  • 605 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)