在恒定位置获取gps更新吗?

时间:2015-08-18 06:08:59

标签: android google-maps

我处于不变的位置但是我连续地获得gps更新并且还在恒定位置绘制线条。如何在恒定位置停止gps更新?

scheduler = Executors.newSingleThreadScheduledExecutor();
        scheduler.scheduleAtFixedRate(new Runnable() {
            public void run() {

                getActivity().runOnUiThread(new Runnable() {

                    public void run() {
                        gps = new GPSTracker(getActivity());
                        double latitude = gps.getLatitude();
                        double longitude = gps.getLongitude();
                        if(latitude>0.0&&longitude>0.0){
                        Toast.makeText(
                                getActivity(),
                                "Your Location is - \nLat: " + latitude
                                        + "\nLong: " + longitude,
                                Toast.LENGTH_SHORT).show();
                        }

                        // Creating a LatLng object for the current location

                        LatLng latLng = new LatLng(latitude, longitude);

                        RouteManager.sourceMarker(getActivity(), latLng,
                                googleMap, markpos, 0);
                        markpos++;

                        points.add(latLng);// addding Latlng to points array

                        Log.d("pointssize", "pointskal--->" + points.size());
                        Double distance = 0.0;
                        //if more than one point we can find duplicate points getting or not,if getting duplicate we remove duplicate point
                        if (points.size() > 1) {
                            // 2.comparing prev and nextlatitudes and longitudes
                            boolean duplicate = routemanage.isDuplicate(points,
                                    googleMap);

                            if (duplicate) {
                                points.remove(points.size() - 1);
                                Log.d("pointssize", "pointskalremnoveafter--->"
                                        + points.size());
                                duplicate = false;
                            } else {
                                int size = points.size();
                                //if not duplicate we can find out the distance

                                distance = routemanage.findDistanceOnRoute(
                                        points.get(size - 2).latitude,
                                        points.get(size - 2).longitude,
                                        points.get(size - 1).latitude,
                                        points.get(size - 1).longitude);
                                Log.d("sorrry", "distance initaial" + distance);


                                if (distance < 1) {
                                    //if distance is less than 1 meter we simply remove the point

                                    points.remove(points.size() - 1);
                                    Log.d("pointssize",
                                            "distance lessthan 1--->"
                                                    + points.size());
                                } else {
                                    // we have to check distance >1 m we can draw the route
                                    sum = sum + distance;
                                    RouteManager.drawRoute(getActivity(),
                                            points, googleMap, sum);
                                    Log.d("sorrry", "sorry dad sum" + sum);
                                    settingmaprunDetails(points.get(size - 1),
                                            sum);
                                }

                                duplicate = true;

                            }// else
                        }// if


                        //if points size is <=1 we can't draw the route
                        else if (points.size() == 1) {
                            settingmaprunDetails(points.get(0), 0.0);
                        }

                    }

我附加屏幕截图请看一次,并给我解决方案,以避免在谷歌地图上绘制路线的笨拙。

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以在GPSTracker(创建locationManager)的某处设置Smallest Displacement。例如:

                    locationManager.requestLocationUpdates(
                            LocationManager.GPS_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

设置最小位移设置位置更新之间的最小位移(以米为单位)。默认情况下,该值为0.您可以使用合理的值减少信号抖动。

相关问题