如何增加我的起始位置的准确性? [英] How to increase the accuracy of my start position?

查看:132
本文介绍了如何增加我的起始位置的准确性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以增加我的起始位置的精度?我的标记总是赶附近位置点我的出发点不是盯着点。

Can I increase the accuracy of my starting position? My marker always catch the near position point of my starting point and not the staring point.

以下是我的编码:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        mgr = (LocationManager) getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria(); // Position Supporter Standard
        bestProvider = mgr.getBestProvider(criteria, true); // Choose the Best
                                                            // Positon
        Location location = mgr.getLastKnownLocation(bestProvider);
        latitude1 = gps.getLatitude(location);
        longitude1 = gps.getLongitude(location);

        // Getting reference to SupportMapFragment of the activity_main
        SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);

        // Getting Map for the SupportMapFragment
        map = fm.getMap();

        // Enable MyLocation Button in the Map
        map.setMyLocationEnabled(true);

    } // OnCreate

    // start from second page
    protected void onStart() {
        super.onStart();
        loadMap();
    }

    // Marker first point
    private void loadMap() {
        // latitude1 = gps.getLatitude(location);
        // longitude1 = gps.getLongitude(location);

        LatLng position = new LatLng(latitude1, longitude1);
        Toast.makeText(getApplicationContext(),
                "LOADlat1:" + latitude1 + " / " + "LOADlog1:" + longitude1,
                Toast.LENGTH_LONG).show();

        // Instantiating MarkerOptions class
        MarkerOptions options = new MarkerOptions();

        // Setting position for the MarkerOptions
        options.position(position);

        // add marker
        map.addMarker(options);
        Log.i("Running+", "Options3: " + String.valueOf(position));
        Log.i("Running+", "Options3: " + String.valueOf(options));

        SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);

        map = fm.getMap();

        map.setMyLocationEnabled(true);

    }

这是我的标志功能的问题?任何人都可以帮我解决这个问题?

It is my marker function problem? Anyone can help me to fix this?

×××我的位置绘制路径code×××

×××My On Location Draw Path Code×××

LocationListener onLocationChange = new LocationListener(){ 
     @Override
     public void onLocationChanged(Location location) {  
         if (location != null) {
            Toast.makeText(getApplicationContext(), "Location NO EQUAL NULL AND START!", Toast.LENGTH_LONG).show();

            GPSTracker1 gps2;
            gps2 = new GPSTracker1(MainActivity2.this);

            latitude2 = gps2.getLatitude();
            longitude2 = gps2.getLongitude();                   

                str_origin = "origin="+ latitude1 +","+ longitude1;
            //Log.i("Running+", "Origin Status: " + str_origin);

            // Destination of route
            String str_dest2 = "destination="+ latitude2 +","+ longitude2;      
            //Log.i("LOCATION+", "Destination Status: " + latitude2 + ", " + longitude2);



            // Sensor enabled
            String sensor = "sensor=false";         

            // Building the parameters to the web service
            String parameters = str_origin+"&"+str_dest2+"&"+sensor;


                    // Output format
                    String output = "json";


                    // Building the url to the web service
                    String url2 = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters;
                    //Log.i("Running+", "Map Get Location: " + url);
                    DownloadTask downloadTask2 = new DownloadTask();

                    downloadTask2.execute(url2);                                    


                Toast.makeText(getApplicationContext(), "Location Change 123!!", Toast.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(), "lat1:" + latitude1 + " / " + "log1:" + longitude1, Toast.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(), "lat2:" + latitude2 + " / " + "log2:" + longitude2, Toast.LENGTH_LONG).show();

                // Getting reference to SupportMapFragment of the activity_main
                SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);

                // Getting Map for the SupportMapFragment
                map = fm.getMap();

                // Enable MyLocation Button in the Map
                map.setMyLocationEnabled(true);     

                Toast.makeText(getApplicationContext(), "Location Change Map!!", Toast.LENGTH_LONG).show();
         }


        }  



        public void onProviderDisabled(String arg0) {  

        }  
        public void onProviderEnabled(String arg0) {  

        }  
        public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 

        }

    };

我可以做两个固定点绘制路径已经但是我希望做真正的步行时间和你走绘制的路径。上面是我的onlocation变化平局路径code,但它有一些bug。它将绘制路径的一半,将不会继续画agian?任何人可以帮助我,或者建议我更多更好的方法来做到这一点?

I can do draw path from two fix point already but I want do the real time walk and draw the path of you walk. Upper is my onlocation change draw path code, but it have some bug. It will draw the path to half and will no continue draw agian? Can anybody help me or suggest me more better method to do this?

推荐答案

的完全匹配的蓝点的位置,使用

The exactly match the "blue dot" position, use

map.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
    ...
});

使用的LocationManager 不屈从 OnMyLocationChangeListener 得到相同的结果,因为这是使用不同的提供商:GPS网络融合

Using LocationManager will never yield the same result you get from OnMyLocationChangeListener, because this it is using a different provider: "gps" or "network" vs. "fused".

这篇关于如何增加我的起始位置的准确性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆