Mapbox开始导航的时间严重延迟

时间:2019-07-12 08:21:53

标签: java android mapbox

我已经从此处https://docs.mapbox.com/android/navigation/examples/waypoint-navigation/实现了mapbox android waypoint导航示例,但改用我自己的位置开始。在OnCreate方法中,我从MainActivity传递位置和目的地。

当我设置SimulationRoute = true时,导航总是完美启动而没有延迟。但是,在大多数情况下,将SimulatorRoute = false设置为false时,导航屏幕会卡住(请参阅stuck screen),并且导航通常要花费1分钟以上的时间才能最终启动。启动时间有时从2秒到2分钟不等。如何加快导航的启动速度?

此错误可在其他设备上重现。互联网连接不是问题。

我相信,当NavigationView.startNavigation(navigationViewOptions);时屏幕会卡住。被执行。但是由于控制台日志没有给我任何反馈,所以为什么卡住了 (或者至少我不理解)我真的不知道如何进行。

@SuppressLint("MissingPermission")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        mDatabase = FirebaseDatabase.getInstance().getReference();
        setTheme(R.style.Theme_AppCompat_NoActionBar);
        super.onCreate(savedInstanceState);
        //
        Intent intent = getIntent();
        Double driverDestinationLong = intent.getDoubleExtra("driverDestinationLong", 0);
        Double driverDestinationLat = intent.getDoubleExtra("driverDestinationLat", 0);
        driverDestinationPoint = Point.fromLngLat(driverDestinationLong, driverDestinationLat);

        Double driverStartLong = intent.getDoubleExtra("driverStartLong",0);
        Double driverStartLat = intent.getDoubleExtra("driverStartLat",0);

        Point driverStartPoint = Point.fromLngLat(driverStartLong, driverStartLat);

        // set default driverlocation as received through the intent
        Double driverLocationLong = intent.getDoubleExtra("driverLocationLong",0);
        Double driverLocationLat = intent.getDoubleExtra("driverLocationLat",0);
        simulateRoute = intent.getBooleanExtra("simulateRoute", true);

        recentDriverLocation = Point.fromLngLat(driverLocationLong, driverLocationLat);

        points.add(driverStartPoint);
        points.add(driverDestinationPoint);
        Log.d("NavActivity","onCreate");

        setContentView(R.layout.activity_navigation);
        navigationView = findViewById(R.id.navigationView);
        navigationView.onCreate(savedInstanceState);
        navigationView.initialize(this);

        user = FirebaseAuth.getInstance().getCurrentUser();

    }

(...)

    @Override
    public void onNavigationReady(boolean isRunning) {
        fetchRoute(points.remove(0), points.remove(0));
        Log.d("NavActivity","onNavigationReady");
    }

(...)

   @Override
    public void onProgressChange(Location location, RouteProgress routeProgress) {
        lastKnownLocation = location;
        Log.d("NavActivity","onProgressChange");


        // TODO: start Progresschangelistener here to retreive Driver Location! or time remaining etc.

        //send live driver coordinate to server here!

        if (user != null) {
            String uid = user.getUid();
            // Define a listener that responds to location updates
            /*String locationProvider = LocationManager.NETWORK_PROVIDER;*/
            // Or use LocationManager.GPS_PROVIDER

                            /*Location lastKnownLocationFix = locationManager.getLastKnownLocation(locationProvider);
                            List<Double> list = Arrays.asList(lastKnownLocationFix.getLongitude(), lastKnownLocationFix.getLatitude());
                            mDatabase.child("DriverLocations").child(uid).setValue(list);*/

            List<Double> list = Arrays.asList(location.getLongitude(), location.getLatitude());
            mDatabase.child("DriverLocations").child(uid).setValue(list);
        }
        else {
            // No user is signed in
            Log.d("user:","no user signed in");
        }


    }

    private void startNavigation(DirectionsRoute directionsRoute) {
        Log.d("NavActivity","startNavigation");
        NavigationViewOptions navigationViewOptions = setupOptions(directionsRoute);
        navigationView.startNavigation(navigationViewOptions);
    }

(...)

    private void fetchRoute(Point origin, Point destination) {
        Log.d("NavActivity","fetchRoutestarted");
        NavigationRoute.builder(this)
                .accessToken(Mapbox.getAccessToken())
                .origin(origin)
                .destination(destination)
                .alternatives(true)
                .build()
                .getRoute(new Callback<DirectionsResponse>() {
                    @Override
                    public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
                        startNavigation(response.body().routes().get(0));
                        Log.d("NavActivity","fetchRouteOnRespone");

                    }

                    @Override
                    public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
                        Log.e("navifail", "Error: " + throwable.getMessage());
                    }
                });
    }

    private NavigationViewOptions setupOptions(DirectionsRoute directionsRoute) {
        Log.d("NavActivity","NavigationViewOptions");
        dropoffDialogShown = false;

        NavigationViewOptions.Builder options = NavigationViewOptions.builder();
        options.directionsRoute(directionsRoute)
                .navigationListener(this)
                .progressChangeListener(this)
                .routeListener(this)
                .shouldSimulateRoute(simulateRoute);
        return options.build();
    }


我希望导航立即启动,不会延迟。实际结果是,在导航启动之前,大部分时间屏幕停留在1分钟以上。

控制台日志中有趣的部分是(23:16:07-23:17:10)。屏幕和控制台日志在那里暂停一分钟,直到它们继续。也许locationupdatespendingintent有问题?

  

2019-07-11 23:16:06.940 29275-29275 / com..carcombo   I / TextToSpeech:已成功绑定到com.google.android.tts 2019-07-11   23:16:07.113 29275-29275 / com..carcombo D / Nav活动:   fetchRouteOnRespone 2019-07-11 23:16:07.117   29275-29275 / com..carcombo I / TextToSpeech:已连接至   ComponentInfo {com.google.android.tts / com.google.android.tts.service.GoogleTTSService}   2019-07-11 23:16:07.163 29275-30794 / com..carcombo   I / TextToSpeech:建立与   ComponentInfo {com.google.android.tts / com.google.android.tts.service.GoogleTTSService}   2019-07-11 23:16:07.539 29275-29275 / com..carcombo I / zygote64:   显式并发复制GC释放了93886(8MB)AllocSpace对象,   47(1952KB)LOS对象,50%空闲,14MB / 28MB,总共暂停250us   398.928ms 2019-07-11 23:16:07.980 29275-29275 / com.carcarbo I / zygote64:显式并发复制GC已释放104026(8MB)   AllocSpace对象,0(0B)个LOS对象,57%空闲,8MB / 20MB,已暂停   207us总159.533ms 2019-07-11 23:16:07.981   29275-29291 / com..carcombo I / zygote64:WaitForGcToComplete   在HeapTrim上阻止HeapTrim持续140.899毫秒2019-07-11 23:17:10.223   29275-29275 / com..carcombo D / LoadedApk:   ZTEPOINT_BR_STATS |完成   注册:com.mapbox.android.telemetry.location.LocationUpdatesBroadcastReceiver@9157e26 |用于   意图   com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED | mRegistered = true | mOrderedHint = true | cost:2   2019-07-11 23:17:10.282 29275-29275 / com..carcombo   W / StaticLayout:maxLineHeight不应为-1。 maxLines:2   lineCount:2 2019-07-11 23:17:10.284 29275-29275 / com..carcombo   W / StaticLayout:maxLineHeight不应为-1。 maxLines:2   lineCount:2 2019-07-11 23:17:10.285 29275-29275 / com..carcombo   W / StaticLayout:maxLineHeight不应为-1。 maxLines:2   lineCount:2 2019-07-11 23:17:10.287 29275-29275 / com..carcombo   W / StaticLayout:maxLineHeight不应为-1。 maxLines:2   lineCount:2 2019-07-11 23:17:10.319 29275-29275 / com..carcombo   D /驱动程序位置值:: DataSnapshot {键= 0,值= 13.2971212}   2019-07-11 23:17:10.550 29275-30810 / com..carcombo   W / Mbgl-HttpRequest:由于永久错误,请求失败:已取消   2019-07-11 23:17:10.588 29275-30905 / com..carcombo   W / Mbgl-HttpRequest:由于永久错误,请求失败:已取消   2019-07-11 23:17:10.600 29275-30903 / com..carcombo   W / Mbgl-HttpRequest:由于永久错误,请求失败:已取消

0 个答案:

没有答案