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

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

錯(cuò)誤在空對象引用上調(diào)用虛擬方法'double android.location.Location

錯(cuò)誤在空對象引用上調(diào)用虛擬方法'double android.location.Location

鳳凰求蠱 2019-12-03 16:15:40
我要嘗試做的就是讓用戶獲得他喜歡的類型的位置的列表。例如,如果輸入是醫(yī)院,我的應(yīng)用程序?qū)⑹褂盟阉髯址?Hospital”打開google maps。但是,正如文檔中所建議的那樣,使用geo:0,0?q=hospitaluri等地理編碼顯示了所有坐標(biāo)0緯度和0經(jīng)度附近的醫(yī)院。因此,當(dāng)我嘗試使用以下代碼首先獲取用戶坐標(biāo)時(shí)。問題在于,始終位置始終返回null。我知道一個(gè)事實(shí),只要啟用了位置,另一個(gè)應(yīng)用程序Jarvis就可以輕松地完成任務(wù),如果沒有的話,僅僅是要求用戶這樣做。但是在相同條件下,我的應(yīng)用程序總是崩潰。我做了什么:白天和黑夜都試圖解決此問題。瀏覽了有關(guān)該主題的大量頁面。嘗試了自己的不同代碼。而且它仍然會(huì)發(fā)生。我是Android的初學(xué)者。并且請幫我。有沒有辦法解決我的問題?甚至以為其他應(yīng)用程序可以設(shè)法做到這一點(diǎn)。同時(shí)檢查位置!= null需要ACCESS_FINE_LOCATION權(quán)限,該權(quán)限使我的應(yīng)用程序混亂,導(dǎo)致其始終返回為null。
查看完整描述

3 回答

?
滄海一幻覺

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

這是執(zhí)行此操作的另一種方法,您已經(jīng)使用了保險(xiǎn)絲定位概念,并且對我來說是成功的mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);


是聲明融合的位置


 @SuppressWarnings( {"MissingPermission"})

private void enableLocationComponent() {

    System.out.println("on map click is here in permission///////////////");

    // Check if permissions are enabled and if not request

    if (PermissionsManager.areLocationPermissionsGranted(this)) {


        // Activate the MapboxMap LocationComponent to show user location

        // Adding in LocationComponentOptions is also an optional parameter

        LocationComponent locationComponent = mapboxMap.getLocationComponent();

        locationComponent.activateLocationComponent(this);

        locationComponent.setLocationComponentEnabled(true);

        // Set the component's camera mode

        locationComponent.setCameraMode(CameraMode.TRACKING);


        mFusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {

                    @Override

                    public void onSuccess(Location location) {

                        originLocation=location;

                        // Got last known location. In some rare situations this can be null.

                        if (location != null) {

                            originLocation=location;

                            System.out.println(" permission granted location is in iff ++///////////////"+location);

                        }

                    }

                });


        //originLocation = locationComponent.getLastKnownLocation();

        System.out.println("origin location is that//////////"+originLocation);



    } else {



        permissionsManager = new PermissionsManager(this);

        permissionsManager.requestLocationPermissions(this);

    }

}


@Override

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

    permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);

    Toast.makeText(this, "granted", Toast.LENGTH_LONG).show();

}


@Override

public void onExplanationNeeded(List<String> permissionsToExplain) {

    Toast.makeText(this, R.string.user_location_permission_explanation, Toast.LENGTH_LONG).show();

}


@Override

public void onPermissionResult(boolean granted) {

    if (granted) {

        enableLocationComponent();

    } else {

        Toast.makeText(this, R.string.user_location_permission_not_granted, Toast.LENGTH_LONG).show();``

        finish();

    }

}

查看完整回答
反對 回復(fù) 2019-12-03
  • 3 回答
  • 0 關(guān)注
  • 720 瀏覽

添加回答

舉報(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)