4

電話の場所をサーバーに送信するアプリを作成しています。私が抱えている問題は、アプリを起動するたびに電話がまったく同じgps座標を提供することです。再起動すると座標が変わる可能性がありますが、最初の座標が送信された後、アプリが再起動されるまで同じものが1回送信されます。

コード:

// Contructor etc

public class LocationASYNC extends AsyncTask<Activity, String, Void> {
    private MainActivity m;
    private LocationManager locationManager;
    private Criteria c;

    public LocationASYNC(MainActivity m) {
        this.m = m;
        locationManager = (LocationManager) m
                .getSystemService(Context.LOCATION_SERVICE);
        c = new Criteria();
        c.setAccuracy(Criteria.ACCURACY_FINE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                3000, 0, m);
    }

// Code for finding best location provider and returning location
    private Location findBestLocation() {

            Location location = locationManager
                    .getLastKnownLocation(locationManager.getBestProvider(c, true));

            Log.v("location",
                    "provider: " + locationManager.getBestProvider(c, true));
            // Check if location is null
            if (location != null) {
                Log.v("location", "provider not null");
                // Test if location is more than 100 seconds old
                if (location.getTime() < (System.currentTimeMillis() - 100000)) {
                    Log.v("location", "provider is old(GPS)");
                    // Use network if location is more than 100 seconds (99% chance
                    // location will be gps)
                    location = locationManager
                            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    // Check if network location is more then 100 seconds
                    Log.v("location", "provider: " + location.getProvider());
                    if (location.getTime() < (System.currentTimeMillis() - 100000)) {
                        // Return null if all location data is old
                        Log.v("location", "provider is old (INT)");
                        return null;
                    }
                }
                // Return location if one is less than 100 seconds old
                return location;
            }
            // return null if no location is found
            return null;
        }

This is the output i get from logcat:

02-05 15:31:59.670: V/location(29659): provider: network
02-05 15:31:59.675: V/location(29659): lat: 60.3935485 lon: 5.3114676 time: 1360074627953 acc: 28.757
02-05 15:32:02.685: V/location(29659): provider: gps
02-05 15:32:02.685: V/location(29659): provider not null
02-05 15:32:02.685: V/location(29659): provider is old(GPS)
02-05 15:32:02.690: V/location(29659): provider: network
02-05 15:32:02.690: V/location(29659): lat: 60.3935485 lon: 5.3114676 time: 1360074627953 acc: 28.757
02-05 15:32:05.700: V/location(29659): provider: gps
02-05 15:32:05.700: V/location(29659): provider not null
02-05 15:32:05.705: V/location(29659): provider is old(GPS)
02-05 15:32:05.710: V/location(29659): provider: network
02-05 15:32:05.710: V/location(29659): lat: 60.3935485 lon: 5.3114676 time: 1360074627953 acc: 28.757
02-05 15:32:08.720: V/location(29659): provider: gps
02-05 15:32:08.720: V/location(29659): provider not null
02-05 15:32:08.720: V/location(29659): provider is old(GPS)
02-05 15:32:08.725: V/location(29659): provider: network
02-05 15:32:08.725: V/location(29659): provider is old (INT)

緯度と経度はすべてのログ猫の投稿で同じであり、時間(1980年頃からのミリ秒)も同じです。

私のアプリは一度場所を取得し、再び位置を取得しようとしないようです。

4

1 に答える 1

0

デバイスで GPS が有効になっているかどうか、またはデバイスが GPS をサポートしているかどうかを確認してください。

于 2014-11-10T02:15:59.123 に答える