receiving ambiguous sky screen while loading google map

不羁岁月 提交于 2019-12-10 13:19:41

问题


while loading google map on device i am receiving below screen sometimes.it comes on second load as shown below. otherwise it comes perfectly as normal google map with route I am using SupportmapFragment and get googleMap object as.

 supportMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map_view_fragment);

below is code for displaying map in activity/fragment

public static void drawRouteIntoMap(final List<? extends MapHelper> position, final GoogleMap googleMap) {
        /*List<MapHelper> position = new ArrayList<MapHelper>();
        for (int i = lastPosition; i < maps.size(); i++) {
            position.add(maps.get(i));
        }*/
        final LatLngBounds.Builder mapBounds = new LatLngBounds.Builder();
        if (position.size() > 0 && Validator.isNotNull(googleMap)) {
            googleMap.clear();
            List<PolylineOptions> polylineOptionses = new ArrayList<PolylineOptions>();
            PolylineOptions option = null;
            Boolean lastPause = null;
            for (MapHelper map : position) {
                if (map.isPause()) {
                    if (Validator.isNull(lastPause) || !lastPause) {
                        option = new PolylineOptions().width(5).color(Color.rgb(255, 0, 155)).geodesic(true);
                        polylineOptionses.add(option);
                    }
                    mapBounds.include(new LatLng(map.getLatitude(),map.getLongitude()));
                    option.add(new LatLng(map.getLatitude(), map.getLongitude()));
                } else {
                    if (Validator.isNull(lastPause) || lastPause) {
                        option = new PolylineOptions().width(5).color(Color.rgb(0, 179, 253)).geodesic(true);
                        polylineOptionses.add(option);
                    }
                    mapBounds.include(new LatLng(map.getLatitude(),map.getLongitude()));
                    option.add(new LatLng(map.getLatitude(), map.getLongitude()));
                }
                lastPause = map.isPause();
            }
            for (PolylineOptions options : polylineOptionses) {
                googleMap.addPolyline(options);
            }
            if(Validator.isNotNull(option)){
                //List<LatLng> points = option.getPoints();


                googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
                    @Override
                    public void onMapLoaded() {
                        LatLng startPoint = new LatLng(position.get(0).getLatitude(), position.get(0).getLongitude());
                        googleMap.addMarker(new MarkerOptions().position(startPoint).title("start").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
                        mapBounds.include(startPoint);
                        LatLng endPoint = new LatLng(position.get(position.size() - 1).getLatitude(), position.get(position.size() - 1).getLongitude());
                        mapBounds.include(endPoint);
                        googleMap.addMarker(new MarkerOptions().position(endPoint).title("finish").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
                        googleMap.setPadding(15, 205, 10, 110);
                        googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(mapBounds.build(), 0));
                        //googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(mapBounds.build(), 10));
                        googleMap.moveCamera(CameraUpdateFactory.zoomOut());

                    }
                });
            }

        }
    }


 supportMapFragment.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                if (Validator.isNotNull(googleMap)) {
                    googleMap.setMyLocationEnabled(false);
                    googleMap.clear();
                    googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
                        @Override
                        public void onMapClick(LatLng latLng) {
                            if (activity.preferences.isSaveScreen()) {
                                facebook.setChecked(false);
                                twitter.setChecked(false);
                                activity.replaceFragment(new FullMapFragment(), null);
                            }
                            if (!activity.preferences.isSaveScreen()) {
                                activity.preferences.setHistoryScreen(true);
                                activity.replaceFragment(new FullMapFragment(), null);
                            }
                        }
                    });
                    if (gps) {
                        nonGpsSummary.setVisibility(View.GONE);
                        List<HistoryMap> historyMaps = new ArrayList<HistoryMap>();
                        if (Validator.isNotNull(activity.preferences.getUserHistory().getHistoryMaps())) {
                            historyMaps.addAll(Arrays.asList(activity.preferences.getUserHistory().getHistoryMaps()));
                        }
                        if (historyMaps.size() > 0) {
                            if (Validator.isNotNull(googleMap)) {
                              drawRouteIntoMap(historyMaps, googleMap);
                            }
                        } else {
                            mapFrame.setVisibility(View.GONE);
                        }
                    } else {
                        gpsSummary.setVisibility(View.GONE);
                    }
                }
            }
        });

this question is in relation with zoom over specific route google map. by using that i get proper route with mapbounds but i m not getting why this screen is displaying.

i am not receiving cordinates 0.0 i debug that,api key is also proper.


回答1:


You are calling moveCamera twice. The first one tries to move the camera but the second one doesn't wait for the first one to end and performs the zoom out.

This may not happen all the times and may behave differently on different devices.

The best option is to set a padding on your CameraUpdateFactory.newLatLngBounds(mapBounds.build(), 0) instead of 0




回答2:


This problem occurs when your coordinates are not properly set. Make sure the coordinates that you are using is pointing in the land to get the maps correctly. Another possible reason is your API key is not working, try to generate new API key for this project.

For more information, check these related SO questions.

  • Android google maps return error and blue screen

  • Blue screen in Android Google Maps



来源:https://stackoverflow.com/questions/40086860/receiving-ambiguous-sky-screen-while-loading-google-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!