com.google.android.gms.maps.model.LatLngBounds $ Builder.build的com.google.android.gms.common.internal.Preternals.checkState处没有包含点

时间:2019-04-22 02:16:18

标签: android

在此行出现错误。

LatLngBounds bounds = builder.build();

我的代码

private void getDicrection() {
        currentPosition = new LatLng( Common.mLastLocation.getLatitude(), Common.mLastLocation.getLongitude() );

        String requestApi = null;
        try {
            requestApi = "https://maps.googleapis.com/maps/api/directions/json?" + "mode=driving&" + "transit_routing_preference=less_driving&" + "origin="
                    + currentPosition.latitude + "," + currentPosition.longitude + "&" + "destination=" + destination + "&" + "key=" + getResources().getString( R.string.google_direction_api );
            Log.d( "DEV", requestApi ); //print URL for debug
            mService.getPath( requestApi ).enqueue( new Callback<String>() {
                @Override
                public void onResponse(Call<String> call, Response<String> response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response.body().toString());
                        JSONArray jsonArray = jsonObject.getJSONArray("routes");
                        for(int i =0; i<jsonArray.length();i++)
                        {
                            JSONObject route = jsonArray.getJSONObject(i);
                            JSONObject poly = route.getJSONObject("overview_polyline");
                            String polyline = poly.getString("points");
                            polyLineList = decodePoly(polyline);

                        }
                        //adjusting bounds
                        LatLngBounds.Builder builder = new LatLngBounds.Builder();
                        for(LatLng latLng:polyLineList)
                            builder.include(latLng);
                        LatLngBounds bounds = builder.build();
                        CameraUpdate mCameraUpdate  = CameraUpdateFactory.newLatLngBounds(bounds, 2);
                        mMap.animateCamera(mCameraUpdate);


                        polylineOptions = new PolylineOptions();
                        polylineOptions.color( Color.GRAY );
                        polylineOptions.width( 5 );
                        polylineOptions.startCap( new SquareCap() );
                        polylineOptions.endCap( new SquareCap() );
                        polylineOptions.jointType( JointType.ROUND );
                        polylineOptions.addAll( polyLineList );
                        greyPolyline = mMap.addPolyline( polylineOptions );

                        blackPolylineOptions = new PolylineOptions();
                        blackPolylineOptions.color( Color.BLACK );
                        blackPolylineOptions.width( 5 );
                        blackPolylineOptions.startCap( new SquareCap() );
                        blackPolylineOptions.endCap( new SquareCap() );
                        blackPolylineOptions.jointType( JointType.ROUND );
                        blackPolylineOptions.addAll( polyLineList );
                        blackPolyline = mMap.addPolyline( blackPolylineOptions );

                        mMap.addMarker( new MarkerOptions().position( polyLineList.get( polyLineList.size() - 1 ) ).title( "Pickup Location" ) );

                        //Animation
                        ValueAnimator polylineAnimatior = ValueAnimator.ofInt( 0, 100 );
                        polylineAnimatior.setDuration( 2000 );
                        polylineAnimatior.setInterpolator( new LinearInterpolator() );
                        polylineAnimatior.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() {
                            @Override
                            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                                List<LatLng> points = greyPolyline.getPoints();
                                int percentValue = (int) valueAnimator.getAnimatedValue();
                                int size = points.size();
                                int newPoints = (int) (size * (percentValue / 100.0f));
                                List<LatLng> p = points.subList( 0, newPoints );
                                blackPolyline.setPoints( p );
                            }
                        } );

                        polylineAnimatior.start();

                        carMarker = mMap.addMarker( new MarkerOptions().position( currentPosition ).flat( true ).icon( BitmapDescriptorFactory.fromResource( R.drawable.car ) ) );

                        handler = new Handler();
                        index = -1;
                        next = 1;
                        handler.postDelayed( drawPathRunnable, 3000 );
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(Call<String> call, Throwable t) {

                }
            } );

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

错误


java.lang.IllegalStateException: no included points
        at com.google.android.gms.common.internal.Preconditions.checkState(Unknown Source)
        at com.google.android.gms.maps.model.LatLngBounds$Builder.build(Unknown Source)
        at com.taxitranspot.View.Home$5.onResponse(Home.java:366)
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)


    --------- beginning of crash
2019-04-22 08:58:42.491 2643-2643/com.dacs.sict.htxv.taxitranspot E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.taxitranspot, PID: 2643
    java.lang.IllegalStateException: no included points
        at com.google.android.gms.common.internal.Preconditions.checkState(Unknown Source)
        at com.google.android.gms.maps.model.LatLngBounds$Builder.build(Unknown Source)
        at com.taxitranspot.View.Home$5.onResponse(Home.java:366)
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

期待所有帮助者。 谢谢!

0 个答案:

没有答案