Google Places API double Latitude: попытка чтения из поля ссылки на нулевой объект - PullRequest
0 голосов
/ 03 августа 2020

Я столкнулся с проблемой API Google Places, когда мне нужно использовать автозаполнение для поиска мест, но, к сожалению, я не могу указать на c место, так как широта не читается. , request = 65661, result = -1, data = Intent {(has extras)}} для действия {............ MainActivity}: java .lang.NullPointerException: попытка чтения из field 'double com.google. android .gms.maps.model.LatLng.latitude' в ссылке на нулевой объект

    public void onAddressFound(String address, double latitude, double longitude, String geocodeobject) {
        Utils.printLog("address", ":" + address);
        geocodeobject = Utils.removeWithSpace(geocodeobject);
            isDestinationMode = true;
            mainAct.configDestinationMode(isDestinationMode);
            mainAct.onAddressFound(address);
        }
        mainAct.currentGeoCodeObject = geocodeobject;

        if (mainAct.noloactionview.getVisibility() == View.VISIBLE) {
            area2.setVisibility(View.GONE);
        }
    }

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Utils.SEARCH_PICKUP_LOC_REQ_CODE) {
            isclickablesource = false;
        }
        if (requestCode == Utils.SEARCH_PICKUP_LOC_REQ_CODE && resultCode == mainAct.RESULT_OK && data != null && gMap != null) {

            if (resultCode == mainAct.RESULT_OK) {
                Place place = Autocomplete.getPlaceFromIntent(data);
                Utils.printLog(TAG, "Place:" + place.toString());

                pickUpLocTxt.setText(place.getAddress());
                sourceLocSelectTxt.setText(place.getAddress());

                LatLng placeLocation = place.getLatLng();
                this.placeLocation = placeLocation;
                LatLng latLngTarget;
                latLngTarget = new LatLng(placeLocation.latitude, placeLocation.longitude);

                CameraPosition cameraPosition = new CameraPosition.Builder().target(latLngTarget)
                        .zoom(gMap.getCameraPosition().zoom).build();
                gMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));


                mainAct.pickUpLocationAddress = place.getAddress();
                if (mainAct.loadAvailCabs != null) {
                    mainAct.loadAvailCabs.pickUpAddress = mainAct.pickUpLocationAddress;
                }
                mainAct.pickUpLocation.setLatitude(placeLocation.latitude);
                mainAct.pickUpLocation.setLongitude(placeLocation.longitude);

                if (mainAct.cabSelectionFrag != null) {
                    mainAct.cabSelectionFrag.findRoute();
                }

                CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(placeLocation, 14.0f);

                if (gMap != null) {
                    gMap.clear();
                    placeMarker = gMap.addMarker(new MarkerOptions().position(placeLocation).title("" + place.getAddress()));
                    gMap.moveCamera(cu);
                }

            } else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
                Status status = Autocomplete.getStatusFromIntent(data);

                generalFunc.showMessage(generalFunc.getCurrentView(getActivity()),
                        status.getStatusMessage());
            } else if (requestCode == mainAct.RESULT_CANCELED) {

            }

        } else if (requestCode == Utils.SEARCH_DEST_LOC_REQ_CODE && resultCode == mainAct.RESULT_OK && data != null && gMap != null) {

            mainAct.setDestinationPoint(data.getStringExtra("Latitude"), data.getStringExtra("Longitude"), data.getStringExtra("Address"), true);


            if (mainAct.cabSelectionFrag != null) {
                mainAct.cabSelectionFrag.findRoute();
            }

            CameraPosition cameraPosition = new CameraPosition.Builder().target(
                    new LatLng(generalFunc.parseDoubleValue(0.0, data.getStringExtra("Latitude")),
                            generalFunc.parseDoubleValue(0.0, data.getStringExtra("Longitude"))))
                    .zoom(gMap.getCameraPosition().zoom).build();
            gMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

            mainAct.addcabselectionfragment();

            menuImgView.setVisibility(View.GONE);
            backImgView.setVisibility(View.VISIBLE);


        } else if (requestCode == Utils.PLACE_AUTOCOMPLETE_REQUEST_CODE) {
            isclickabledest = false;
            if (resultCode == mainAct.RESULT_OK) {
                Place place = Autocomplete.getPlaceFromIntent(data);

                LatLng placeLocation = place.getLatLng();

                mainAct.setDestinationPoint(placeLocation.latitude + "", placeLocation.longitude + "", place.getAddress().toString(), true);


                destLocTxt.setText(place.getAddress().toString());
                destLocSelectTxt.setText(place.getAddress().toString());


                if (mainAct.cabSelectionFrag != null) {
                    mainAct.cabSelectionFrag.findRoute();
                }

                mainAct.addcabselectionfragment();

                CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(placeLocation, 14.0f);


                if (gMap != null) {
                    gMap.clear();
                    gMap.moveCamera(cu);
                }
                destLocTxt.setText(place.getAddress());
                destLocSelectTxt.setText(place.getAddress());


                menuImgView.setVisibility(View.GONE);
                backImgView.setVisibility(View.VISIBLE);


            } else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
                Status status = Autocomplete.getStatusFromIntent(data);


                generalFunc.showMessage(generalFunc.getCurrentView(getActivity()),
                        status.getStatusMessage());
            } else if (requestCode == mainAct.RESULT_CANCELED) {

            }
        }
    }```
...